Inbound Integration

abjaffrey
Giga Guru

Hi all,

 

I tried to executed this code by following the steps mentioned from the learn path in servicenow.

The expected outcome is to generate the city based on IP but its not generating

 

BR:

 

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

    // Add your code here
     try {
 var r = new sn_ws.RESTMessageV2('x_1582528_iplookup.IPInfo', 'GetIPInfo');
 r.setStringParameterNoEscape('specific_field', 'city');
 r.setStringParameterNoEscape('ipaddress', 'current.ip_address');

//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);

//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');

//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);

 var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
}
catch(ex) {
 var message = ex.message;
}

var responseObj = JSON.parse(responseBody);
current.city = responseObj.city;
gs.info('City = ' + current.city);
current.update();

catch(err)
{
    gs.info("Uncaught error : " + err);
    var message = ex.message;
}

})(current, previous);
 
The log shows this
abjaffrey_0-1733744662204.png

 

9 REPLIES 9

Runjay Patel
Giga Sage

Hi @abjaffrey ,

 

Are you getting 200 Status?

Try testing from rest message and see what value are you getting.

RunjayPatel_0-1733751961961.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Im getting the test results as positive witth 200 and city/region as the value based on the argument passed but when i tried to ser a field on the table with the business rule its not working i checked the log it mentioned “city=“

Hi @abjaffrey ,

 

print responseBody and whether city value is coming or not.

if coming then share that details 

can you help me with where to print it