Calling Back end suitelet from User event

UserEvent:

let recordId = scriptContext.newRecord.id;
                    let billObj = toGetBillingScheduleDetails(recordId);
                    let domain = url.resolveDomain({
                        hostType: url.HostType.APPLICATION 
                    });
                    var suiteletPath  = url.resolveScript({
                        scriptId: 'customscript_jj_sl_assignresourcetotask',
                        deploymentId: 'customdeploy_jj_sl_assignresourcetotask',
                        returnExternalUrl: true
                    });
                    let fullUrl = 'https://' + domain + suiteletPath;
                    var response = https.post({
                        url: suiteletPath,
                        headers: {
                            'Content-Type': 'application/json',
                            'User-Agent' : 'Mozilla/5.0'
                        },
                        body: JSON.stringify({
                            billObj
                        })
                    });
                    log.debug('Suitelet Response', response);

Suitelet:

  const onRequest = (scriptContext) => {
            try {
                if (scriptContext.request.method === 'GET') {
                    log.debug('suitlet in get')
                    return 'success'

                } else if (scriptContext.request.method === 'POST') {
                    var body = scriptContext.request.body;
                    var parsedData = JSON.parse(body);
                    billObjArray = parsedData.billObj
                    log.debug('billObjArray', billObjArray);
                    if (billObjArray.length > 0) {
                        billObjArray.forEach(processBillingScheduleDetail);
                    }
                }
            } catch (err) {
                log.error('error@onRequest', err)
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *