I am able to correctly hit the ServiceNow API and get a response but it comes back in an array:
{
“statusCode”:200
“body”: {
“result”: [
{
“u_application_technical_lead.name”: “My Name”
“u__ctb_system_director.name”: “Another Name”
“name” : “ABC- Application”
}
]
}
I tried to use it with “context.get_info.response.body.result.u_application_technical_lead.name” but I think the “.name” is messing it up or I need to do something with teh array like “result[0]” Im not sure how to use the response in a message. I assume it has to do with the “result” being an array.
TIA
Anthony
@anthony.hibbitts
Say you need the result> name, you will need to use
context.get_info.response.body.result[0].name
However, although JSON response can technically have “.” in the string, the platform may have difficulty parsing it. So you may need to massage the data receive, cleanse the response, and replace all “.” with “_”.
Example: “u__ctb_system_director.name”
to “u__ctb_system_director_name”
It will be better if you have control of the third-party system to not have “.” inside the JSON keys.
@santhosh.myadam
So unfortunately the data source is ServiceNow and cant be changed but if I am understanding I can use like this?
context.get_info.response.body.result[0].u_application_technical_lead"."name
Does that look right?
TIA
@anthony.hibbitts Does it work for you? Even if it does I will need to get this reviewed the the dev team once so that backward compatibility can be ensured.
No it doesnt not work I tried both:
context.get_info.response.body.result[0].u_application_technical_lead"."name and
context.get_info.response.body.result[0].“u_application_technical_lead.name”
Not sure how to massage the data when it comes through.
@anthony.hibbitts
I think I figured out a solution and it may not need data massaging (otherwise regex based replaceall should have been
Take this code for example:
var res = {
"statusCode": 200,
"body": {
"result": [{
"u_application_technical_lead.name": "My Name",
"u__ctb_system_director.name": "Another Name",
"name": "ABC- Application"
}
]
}
};
console.log(res.body.result[0]["u_application_technical_lead.name"]);
If I execute this in the browser console, it will work.
Same way, in the bot also, if I set a context value in the script node like
And print in a message node like this
It will work.
1 Like