want to know whats wrong in my code

mishrarakes
Tera Contributor

I am learning about serviceNow integeration , and fetching api from outside api using serviceNow Outbound Integration using request and made a new field on want to add  the api details using script in Business rule , but i don't know why its not working , I am attaching the important screenshots here can someone help.

 

 

```

(function executeRule(current, previous /*null when async*/)
 {

    // Add your code here

try {
 var r = new sn_ws.RESTMessageV2('x_1332747_iplook_0.ipLookup', 'Default GET');

  r.setQueryParameter('ip',current.enter_your_ip);
 var response = r.executeAsync();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();

 var responseObject = JSON.parse(responseBody);


 current.country = responseObject.country_code3;
 current.city = responseObject.city;
 current.currency = responseObject.currency.name;
 
 current.update();
}
catch(ex) {
 var message = ex.message;
}

})(current, previous);
```
 
fyi : referred techwithpri servicenow integration playlist
5 REPLIES 5

Hello @mishrarakes, Thanks for the response. as mentioned others too, can you please try below steps: 

1- change var response = r.executeAsync(); to var response = r.execute();

2- print the response whether you receive it fine - gs.info(responseBody)

3 - if #2 is not printing anything, you can try to debug the API call and will understand the problem. you can try postman too if you dont receive response back. you can avoid this step if #2 works fine

4 - If all the above works fine and you find problem in updating the record, then you can try to comment out current.update()

 

Regards,

Nishant