Hi all, My <https.post> is not working in client s...
# general
g
Hi all, My https.post is not working in client script, but same code is working in User event.does anyone have any idea?
b
standard information you need to share are any errors
and the code
e
Are you trying to call a NetSuite URL or some other external URL?
g
I am calling an external url
Its giving Unexpected error
e
Remember that when running in client script, this call is happening from the user’s browser. When running from the user event script, it’s running from NetSuite’s servers. You need to consider how that difference might impact things. For example, is your user behind a firewall that might be blocking the external URL. There are many other reasons that could be possibilities. I would try to catch the error and log it.
g
yes i tried to log it using try catch & I got unexpected error
e
Post some code and maybe there’s something that will stand out.
g
this is the sample code
/** ◦ @NApiVersion 2.1 ◦ @NScriptType ClientScript */ define(['N/https'], function (https) { function saveRecord(){ //Define JSON string to send var JSONstring = { ID: 0, Status: 8, Priority: 2, CompanyID:1111, QueueID: 29682833, AssignedResourceID: 29682887, AssignedResourceRoleID:29683464, Description:'FILL IN THE DESCIPTION PLEASE!', Title:'NEW TICKET - (CHANGE THIS BEFORE SAVING!)' }; //Define headers var JSONheaders = new Array(); JSONheaders['APIIntegrationcode'] = 'CNOWCTWHF7JVSHHK4CSVZEQ3NMT'; JSONheaders['Username'] = 'tuohffgh@test.com'; JSONheaders['Secret'] = 'jF*4E@8t~9nHW$2y0Mk#@f1Pe'; JSONheaders['Content-Type'] = 'application/json'; //Send API call try{ var response = https.post({ url: 'https://webservices16.autotask.net', headers: JSONheaders, body: JSON.stringify(JSONstring) }) } catch{ log.debug({ title:'Failed', details: JSONstring }); } }; return{ saveRecord: saveRecord }; } )
its going in catch section
b
the headers is supposed to be an Object, not an Array
use an Object initializer to create your header object
g
But the same code is working in user event
b
the difference between client and server side code like user events is that they call the netsuite backend differently
client side code is basically a https request to netsuite's server
which requires transforming your parameters to a string
that transformation is different for Arrays and Objects
serverside code doesnt need to do that transformation
g
Ahh okay . So you mean I will have to define header as object- jasonHeader = {};
Hi @battk 🙂 Thanks a lot . It worked