0

I have a User Event and Client Script for my Netsuite system. I added a button on a transaction page. This code works on the User Event beforeLoad function, but for my client script button press function I get an error: Unexpected error and am not sure why it runs fine on one but not the other? I have put in an example url and example data so it is not the exact code.

thank you

    var requestData = {"externUserId":"Tom","externAppName":"Netsuite","externAppScreenTitle":"Bill","Setting":"true"};
    
    requestData = JSON.stringify(requestData);

    var headerObj = new Array();
    headerObj['Content-Type'] = 'application/json';
    headerObj['Accept'] = 'application/json';
    
    var response = https.post({
        url: 'https://test.zzzz.com/myexample/api/SetVisible',
        headers: headerObj,
        body: requestData
    });

1 Answers1

0

Netsuite doesn't expect an array as headers. Your basic code looks correct so try:

    var requestData = {"externUserId":"Tom","externAppName":"Netsuite","externAppScreenTitle":"Bill","Setting":"true"};
    
    requestData = JSON.stringify(requestData);

    var headerObj = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    };
    
    var response = https.post({
        url: 'https://test.zzzz.com/myexample/api/SetVisible',
        headers: headerObj,
        body: requestData
    });
bknights
  • 14,408
  • 2
  • 18
  • 31
  • Wow amazing! It works on the client script now. I don't understand how the user event script accepted the header array? Either way I thought it was a limitation with the client script type with https requests. I changed the user event script to not use an array as well and still works. I'll keep this in mind with my other scripts in the future. Thank you so much bknights! You are so kind to help. – accountdev253 Jul 06 '22 at 18:47