Splitting multi line text in a Transform Script

minaz
Giga Expert

i want to transform (source.description) data which is in this format:

1. Click Website, 2. Enter Login Information, 3. Click Login, ...."

Into an HTML field (target.u_description) in this format:

1. Click Website,

2. Enter Login Information,

3. Click Login"

I tried this in a "Script Background" as follows and it works, I am not sure how to use it in a transform map:

var str = " 1. Click Website, 2. Enter Login Information, 3. Click Login";

var na = str.split(",");

for (var i = 0; i < na.length; i++) {

gs.print(na[i]);

}

Help appreciated.

1 ACCEPTED SOLUTION

jose_valle
ServiceNow Employee
ServiceNow Employee

Hi Minaz,



You might want to try using a script for the source on your transform entry with something like this.



answer = (function transformEntry(source) {


    // Add your code here


  return source.description.split(",").join("\n"); // return the value to be put into the target field


})(source);




Hope this helps.


View solution in original post

6 REPLIES 6

jose_valle
ServiceNow Employee
ServiceNow Employee

Hi Minaz,



You might want to try using a script for the source on your transform entry with something like this.



answer = (function transformEntry(source) {


    // Add your code here


  return source.description.split(",").join("\n"); // return the value to be put into the target field


})(source);




Hope this helps.


minaz
Giga Expert

Hello Jose, thanks for your help.



Although the transform was successful, the data did not split and did not put it in separate lines.



Thanks.


jose_valle
ServiceNow Employee
ServiceNow Employee

Hi Minaz,



I missed that you were updating an html field. You will want to replace "\n" with "<br>" for an html new line.



Thanks,


minaz
Giga Expert

Thank you Jose. That worked. However, another issue has cropped up.



When I am trying to transform:



1. some text 1, 2. some text 2, 3. some text 3, 4. some.........



the HTML or the String field, although get updated with the split data in new lines but the data cuts of at 3. s



1. some text 1,


2. some text 2,


3. s



This also happens even if I am not using any field map script.



Any idea why?