Populate comma separated values in next line

Pallavi65
Tera Contributor

Hi everyone,

There is a string field holding multiple values with comma separated. I want to show the values one below the other instead of comma separated.

Taking the values into an array, and pushing those values one by one into that field like, once we push first object of the array into string field, and while we push the second object of the array into the string field, can we print that below the first value with \n ?

How can we do this? using any onload Client script?

 

 

Can someone help me to achieve this with code?

 

 

Regards,

Pallavi

 

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

Try below script,

updateABC: function(serv, relApp) { 

        var grServ = new GlideRecord('cmdb_ci');
        grServ.addEncodedQuery('sys_id=' + serv);
        grServ.query();
        if (grServ.next()) {
            if (grServ.getDisplayValue('u_rel_app') != relApp) {
                grServ.u_rel_app = relApp.replaceAll(",","\n");
                grServ.setWorkflow(false);
                grServ.update();
            }
        }

        return true;

    },

Let me know if you have any further questions. 
 
Please mark this as Correct or Helpful based on the impact.

Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

9 REPLIES 9

Muhammad Khan
Mega Sage
Mega Sage

Hi Pallavi,

 

Change the String field length to more than 255 characters. See the image below.

find_real_file.png

It will look like this.

find_real_file.png

Then you can utilize the following script.

var arr = [1,2,3,4,5,6,8];

gr.setValue('<your_fiield_name>', arr.join('\n'));
gr.update();

 

hopefully, this will help you.

Hi Muhammad, Thank you. Where should I write this script?? Regards, Pallavi

How do you want this to be achieved ?

From where you will get or are getting values ?

What is the format/structure/datatype of those values ?

A sample would be useful.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you make it with larger length then user can enter the new line for each values.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader