- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2017 09:58 PM
This sounds pretty simple - however I'm unable to get it to work, and I'm afraid I'm overlooking something simple.
I have a workflow that contains a REST Message that POSTs a record into an external system, and I want to take the the ID that gets returned from the POST call and assign it to a field.
The table this is running on is sc_req_item
Here is the offending part of the workflow:
When the POST happens, it replies with a payload like this:
{
"id": 184
}
I can successfully parse this into a variable called "activityOutput.splynx_id", then Post-process this into a variable:
var customer_splynx_id = activityOutput.splynx_id;
I want to assign this value to a string field called 'u_splynx_customer_id' that is on the Company table, which I attempt to do in the next Run Script step.
To be sure, I put the following logging statement on top of the script to ensure that the variables are correctly being assigned:
gs.log("Post Process ID Variable: " + customer_splynx_id + ". Activity Output: " + data.get(17).splynx_id, "Customer Splynx ID Script");
Which they do:
I have tried the following syntax's to set the field value:
var screq = current.GetValue('company');
//var screq = current.GetValue('request.requested_for.company');
var gr = new GlideRecord('core_company');
if (gr.get(screq)) {
gr.u_splynx_customer_id = customer_splynx_id;
gr.update();
}
and also
current.company.u_splynx_id = customer_splynx_id;
current.update();
However the field is not getting updated.
I have tried running the following script manually in Background Scripts:
var customer_splynx_id = '180'
var screq = '0398ca2d4fbae600214efe501310c7ba';
var gr = new GlideRecord('core_company');
if (gr.get(screq)) {
gr.u_splynx_customer_id = customer_splynx_id;
gr.update();
}
And it worked fine.
Can anyone see where I'm going wrong here?
Solved! Go to Solution.
- Labels:
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 08:56 PM
I did the following to make it work:
- Followed Ujjawal's advice and change the capital letter in the getValue
- Added a 15 second delay between the REST Message and the script
- Script looks like this:
var screq = current.getValue('company');
var gr = new GlideRecord('core_company');
if (gr.get(screq)) {
gr.u_splynx_customer_id = data.get(17).splynx_id;
gr.update();
}
Workflow looks like this:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2017 10:34 PM
Hi Jamie,
You can get the full response body by activity.output. In sensor script you can parse the json and can get the required data. Please refer the below code.
var parser = new JSONParser();
var parsedResponse = parser.parse(activity.output);
workflow.scratchpad.id=parsedResponse.id;
Also, You should replace var screq = current.GetValue('company'); with var screq = current.getValue('company');
Hope this helps.
Regards
Ujjawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 04:45 PM
Hi Ujjawal,
Thanks for your reply.
I am parsing the response correctly, and with the gs.log, I can see that the variables are being assigned the correct value.
However I am unable to set that variable to the u_splynx_customer_id on the Company record.
I tried doing your change to current.getValue but it still not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 08:56 PM
I did the following to make it work:
- Followed Ujjawal's advice and change the capital letter in the getValue
- Added a 15 second delay between the REST Message and the script
- Script looks like this:
var screq = current.getValue('company');
var gr = new GlideRecord('core_company');
if (gr.get(screq)) {
gr.u_splynx_customer_id = data.get(17).splynx_id;
gr.update();
}
Workflow looks like this: