I have a Suitecommerce site product page where certain information is appended to url in the form of query paramaters. For example: https://my-ecommerce.com/product/someProduct?referralId=someValue
My objective here is to pass the salesOrder
record to some external API endpoint on product purchase. I accomplished that by deploying a User Event script as follows:
function afterSubmit(type) {
// Url of the external api endpoint to push data
var url = "http://external-url/endpoint/";
// Get the new created record. It returns a nlRecordObj
var record = nlapiGetNewRecord();
// Get the record Id of that created record
var recordId = record.getId();
// Get the record of corresponding record Id and record type
var nlobj = nlapiLoadRecord("salesOrder",recordId);
// To log our request data
nlapiLogExecution("DEBUG","Test",JSON.stringify(nlobj));
// Set Headers for HTTP request
var headers = {"Content-Type":"application/json"};
// Performing HTTP request to our url with our newly created data as payload
var response = nlapiRequestURL(url, JSON.stringify(nlobj), headers);
}
But what I also want to pass is the referralId
along with the salesOrder record from the suitecommerce url.
One solution I thought of is to put the url paramaters in browser's local storage and then fetch it from suitescript. But Suite script does not recognize window.localStorage
.
Any idea how I could accomplish this? A code snippet would be helpful.