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