0

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.

Apar Adhikari
  • 741
  • 1
  • 6
  • 17
  • 1
    The `window` object is not available to server-side scripts such as NetSuite user event scripts. You would have to embed a script on the web page to get the `referralId` parameter and either call a suitelet with it, or add it to a custom field in the sales order which you can then reference from the user event. At least that's one suggestion...hope it helps. – Krypton Jan 11 '19 at 15:05

1 Answers1

0

In the scenario of the referral, if you need one per order you can create one Transaction Body Field and populate that field from the frontend at the moment of adding the item to the cart.

In case that you need to have on referral code by item, you must create a Transaction Item Option and manually add the "value" from the URL into that field.

If you are going to read a URL parameter and save it into NetSuite Backend field be SUPER CAREFUL with a XSS Injection, escape any value and confirm that value is correct before save it.

Martin
  • 128
  • 5