-1

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 });
Adriano Reis
  • 35
  • 1
  • 9
  • Not clear at all, be more precise, what are you doing ? what do you want to do ? some codes ? what are logging ?... – B. Assem Mar 11 '19 at 22:45
  • This is the snippet of code where I get the responder.body. I need to give a record.load in the item and set a field with itemid (97323) that is in the response.body of the log. How do I get the value that comes from the request response? – Adriano Reis Mar 12 '19 at 00:39
  • 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 }); – Adriano Reis Mar 12 '19 at 00:40
  • 1
    You can use the [edit] button to make improvements to your question. – Martin Evans Mar 12 '19 at 07:37

2 Answers2

0

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;
    
Til
  • 5,150
  • 13
  • 26
  • 34
B. Assem
  • 1,058
  • 9
  • 12
0

With the help of friends Tiw and B. So I'm posting the updated code snippet. Thank you all!

if ( response.code == 200 ) {
                var parseBody = JSON.parse(response.body);
                var id_admin = parseBody.idproduto;
                log.audit('id_admin', id_admin);
                var grava_id_admin = load_itemObject.setValue({ fieldId: 'displayname', value: id_admin })
                                                     .save();
            }
Adriano Reis
  • 35
  • 1
  • 9