- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 05:21 AM
I have this Business Rule that keeps returning the follower error and I can't figure out what's wrong:
"Uncaught error: SyntaxError: Unexpected token: u"
Here's the code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('x_275105_iplookup.IPInfo', 'GetIPInfo');
r.setStringParameterNoEscape('specific_field', 'geo');
r.setStringParameterNoEscape('ip_address', 'current.address');
// Convert the json formatted string to a JavaScript Object
var responseObj = JSON.parse(responseBody);
//Set the value of the City field on the IPAddressInfo record
current.city = responseObj.city;
gs.info("City = " + current.city);
current.update();
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(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(err) {
gs.info("Uncaught error: " + err);
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 05:31 AM
second point , why are you using current.update() here
Updated Code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('x_275105_iplookup.IPInfo', 'GetIPInfo');
r.setStringParameterNoEscape('specific_field', 'geo');
r.setStringParameterNoEscape('ip_address',current.address);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var responseObj = JSON.parse(responseBody);
gs.info('status code is'+httpStatus )
current.city = responseObj.city;
gs.info("City = " + current.city);
current.setWorkflow(false);
current.update();
}
catch(err) {
gs.info("Uncaught error: " + err);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 05:25 AM
can you pass the current.address with out quotes.
r.setStringParameterNoEscape('ip_address', current.address);
check the status code in log.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 05:27 AM
r.setStringParameterNoEscape('ip_address', 'current.address');
to be replaced with
r.setStringParameterNoEscape('ip_address', current.address);
THanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 05:31 AM
second point , why are you using current.update() here
Updated Code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('x_275105_iplookup.IPInfo', 'GetIPInfo');
r.setStringParameterNoEscape('specific_field', 'geo');
r.setStringParameterNoEscape('ip_address',current.address);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var responseObj = JSON.parse(responseBody);
gs.info('status code is'+httpStatus )
current.city = responseObj.city;
gs.info("City = " + current.city);
current.setWorkflow(false);
current.update();
}
catch(err) {
gs.info("Uncaught error: " + err);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2019 12:59 PM
Thanks Harshvardhan! That worked!