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

Hi Ankur,

 

We are populating App names using script into a String field. So whenever we create a relationship between an application and server, then in the server record there is a field, and in that the applications will populate automatically with comma separated. But I want to populate them one below the other.

 

Regards,

Pallavi

Share the script here and did you make the field with length as 300 etc?

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

Hi Ankur,

 

            if (grServ.getDisplayValue('u_rel_app') != relApp) {

                grServ.u_rel_app = relApp;

                grServ.update();

            }

        }

        return true;

    },

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

Thank you ABhijit