In Client Script:
In the client script sending multiple HTTPS POST Request
//Https request1
let response1 = https.post({
body: JSON.stringify({
“empId”: empId,
“actiontype”: ‘fetch’
}),
url: window.location.href,
headers: {
‘Content-Type’:‘application/json’
}
})
//Https request2
let response2 = https.post({
body: JSON.stringify({
“”empId”: empId,
“actiontype”: “submit”,
“title”: record.getValue({fieldId: ‘custpage_jj_title’}) || ”,
“toLead”: record.getValue({fieldId: ‘custpage_jj_assign_to’}) || ”,
“status”: record.getValue({fieldId: ‘custpage_jj_status’}) || ”,
“eventaccess”: record.getValue({fieldId: ‘custpage_jj_event_access’}) || ”,
}),
url: window.location.href,
headers: {
‘Content-Type’: ‘application/json’
}
});
In Suitelet Script:
In suitelet handling request and send back response to the client script
let requestBody = JSON.parse(scriptContext.request.body);
let actiontype = requestBody.actiontype;
log.debug(“Action type: “,actiontype);
if(actiontype === ‘fetch’){
let empId = requestBody.empId;
let leadArray = [];
let leadSearch = search.create({
type: search.Type.CUSTOMER,
filters:
[[“isperson”, “is”, “F”],
“AND”,
[“salesteammember”, “anyof”, empId],
“AND”,
[“isinactive”, “is”, “F”],
“AND”,
[“companyname”,“isnotempty”,“”]
],
columns: [‘internalid’, ‘companyname’]
});
leadSearch.run().each(function(result){
let internalid = result.getValue(‘internalid’);
let name = result.getValue(‘companyname’);
let obj = {
[internalid]:name
}
leadArray.push(obj);
return true;
});
//Response for action type: fetch
scriptContext.response.write({
output: JSON.stringify({
success: true,
data: leadArray
}),
contentType: ‘application/json’
});
log.debug(“lead array:”,leadArray);
}
if (actiontype === ‘submit’) {
try {
let empId = requestBody.empId;
let title = requestBody.title;
let toLead = requestBody.toLead;
let status = requestBody.status;
let eventaccess = requestBody.eventaccess;
let eventRec = record.create({
type: record.Type.CALENDAR_EVENT,
isDynamic: true
});
eventRec.setValue({ fieldId: ‘title’, value: title });
eventRec.setValue({ fieldId: ‘status’, value: status });
eventRec.setValue({ fieldId: ‘accesslevel’, value: eventaccess });
let recordId = eventRec.save({
enableSourcing: true,
ignoreMandatoryField: true
});
//Response for action type: submit
scriptContext.response.write({
output: JSON.stringify({
success: true,
data: {
“id”: recordId,
“title”: title,
“url”: redirectUrl
}
}),
contentType: ‘application/json’
});
}