โ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?
โ06-16-2020 12:56 PM
Hi Peter,
I just mocked the $obj, the sl.ensureArray is to cast $obj as array so that I can invoke toObject() function
So, to answer your question about the white-spacesโฆ the toObject function is basically creating key/value pairโฆ the 1st callback generates the key and the 2nd callback generates the value, all you need to do is use the script that defines the key and update what you have
toObject((x,y)=> x.split(โ=โ)[0].trim().replace(/\s/g,โ_โ), (x,y)=> x.split(โ=โ)[1].replace(/[CRLF]/g,โ\r\nโ))
~EmEm