05-24-2020 06:07 AM
I have a pipeline that uses the ServiceNow API Snap to retrieve data about ServiceNow Tasks. The Snap returns the data and I pass through a mapper.
However the ServeirNow form that I am getting data from contains ServiceNow custom variables and these come back from the API as a string and I am struggling to get these into a JSON format.
This is the data after the mapper
{
“number”:“RITM123456”
“etc:123”
“variables”:“Auto ID = 123\n Autoversion ID = 345\n Autoname = SQL stuff\n etc…”
}
I have tried using split and replace, but I cannot get the data into the right format.
How do I get everything into a JSON format?
05-27-2020 12:20 PM
Looks like all you need is a mapper snap.
06-01-2020 07:14 PM
Or in the scenario wherein the objects inside the variables object is dynamic you can always use the merge then filter variables to destroy the variables object 😄
06-15-2020 09:34 AM
Thanks for all your help.
I now have nearly what I am after. but how do I remove the white space and the beginning and end of the field names after the merge, i.e.
in the mapper I see;
$[’ Additional Comments ‘]
$[’ Risk Comments ‘]
$[’ Automation author ']
and I would like to see
$Additional Comments or $Additional_Comments
$Risk Comments or $Risk_Comments
$Automation author or $Automation_author
Thanks
Peter
06-15-2020 11:20 AM
first trim the key then do a replace of spaces with underscore
$obj = " word of the day = my very energetic mother just serve us nine pie[CRLF][CRLF]HeHeheHeHehEhe "
sl.ensureArray($obj).toObject((x,y)=> x.split(‘=’)[0].trim().replace(/\s/g,‘_’), (x,y)=> x.split(‘=’)[1].replace(/[CRLF]/g,‘\r\n’))
06-16-2020 04:46 AM
I dont quite following the link above?
What is the sl in sl.ensure Array?
I switched $obj for my variable name.
I get the following error when I try, Could not compile expression: sl.ensureArray($variables).toO … (Reason: Invalid token: ‘’’ for expression: sl.ensureArray($variables).toO