Search code examples
netsuitesuitescriptsuitescript2.0

NetSuite MapReduce - Capture Data From a Request


I have a script that updates the product data in NetSuite on another system. When this occurs, I get response 200 and json with the product id on the other system. I would like to know how do I get this id (97323), as I need to set a field in the item record in NetSuite.

log screenshot

Here's the code:

var response = admin.post(url_produto_save, 
        {'Authorization': authorization, 'Content-Type': content_type, 'User-Agent-x': user_agent_x }, 
        bodyObject); 
log.audit({ title: 'Response Status', details: response.code }); 
log.audit({ title: 'Response Body', details: response.body });

Solution

  • So you response.body is showing {"status":"ok"... when logged and you want to get the value of the idproduto.

    If I did understand well your request, then you can try two things:

    1. If the "content_type" in your request is "json", then the body answer will be a JSON object and you will be able to use : response.body.idproduto
    2. If that didn't work, then you can parser the "body" and then use it:

      var parsedBody = JSON.parse(response.body);
      var idItem = parsedBody.idproduto;