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,



Does that target field have a limit? Are you able to type more than those characters into that field directly?



I tried with your exact text and it seemed to work ok for me.


split_test.png


minaz
Giga Expert

You are right. It worked for me as well.



Thanks for your Help.