How to break JSON data in to Java Script Newline? Please suggest

Mukesh Singh
Tera Contributor

We have integration in place, where we are receiving data in JSON for Full Address as mentioned below.

"Full_Address": "Plac Andersa 5
61894 Poznan
Poland"

And we want to store this data as below in street field in ServiceNow.

Street : 

Plac Andersa 5

61894 Poznan

Poland

Need to remove(
) from JSON and store into Newline as mentioned above.

1 ACCEPTED SOLUTION

SumanthDosapati
Mega Sage
Mega Sage

Hi @Mukesh Singh ,

You can try below example format.

var text = "Plac Andersa 5
61894 Poznan
Poland";
text = text.split("
").join("\n")
gs.print(text);

//it will print
Plac Andersa 5
61894 Poznan
Poland

 

Regards,

Sumanth

 

View solution in original post

4 REPLIES 4

SumanthDosapati
Mega Sage
Mega Sage

Hi @Mukesh Singh ,

You can try below example format.

var text = "Plac Andersa 5
61894 Poznan
Poland";
text = text.split("
").join("\n")
gs.print(text);

//it will print
Plac Andersa 5
61894 Poznan
Poland

 

Regards,

Sumanth

 

Thanks for your response @Sumanth Dosapati. Its working on same cases but in some cases not working.

For Example :  

"Naomi Building
National Highway Real
Calamba City
4027
Philippines"

Its giving below result.

Naomi Building
National Highway Real&#

It's working fine when I checked in background script

find_real_file.png

Can you try again.

You can open 'scripts - background' from left navigator and try that.

 

Regards,
Sumanth

Its working fine in 'scripts - background'.

But i am using in Transform Map and its not working there in some cases. Target field in the transform map is Street(Field Type : Two Line Text Area).

I have written below code.

answer = (function transformEntry(source) {

    // Add your code here
    var a = source.u_full_address.toString();
    a = a.split("
").join("\n");
    return a;