โ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