Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to show values of String in the select box.

Samiksha2
Mega Sage

Hi All,

 

I have a requirement to show the string values in the select box.

Samiksha2_0-1706366674755.png

This CSMText field is in account table and these values should be populate in the Catalog item as select box.

Please help in this.

 

Thanks,

Sam

1 ACCEPTED SOLUTION

Hi @Dr Atul G- LNG ,

I have done that.

I have written a script include and Onload cline script

Script Include
getCMS: function() {
        var answer = [];
        var users = this.getParameter('user');
        var grs = new GlideRecord('customer_account');
        grs.addEncodedQuery('customer=true^sys_id=' + users);
        grs.query();
        while (grs.next()) {
            answer.push(grs.u_csmtext.toString());
        }
        return answer.join(',');
    },

Client Script
   var tes = g_form.getValue("u_account");
    var gsr = new GlideAjax('get_csm');
    gsr.addParam('sysparm_name', 'getCSM');
    gsr.addParam('user', tes);
    gsr.getXML(test);

    function test(response) {
        var answers= response.responseXML.documentElement.getAttribute('answer');
        var array = answers.split(',');
        for (var i = 0; i < array.length; i++) {
            g_form.addOption('csm', array[i], array[i]);
        }
    }

 

 

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Samiksha2 

 

Could you please provide lil more details what exactly is use case?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,

 

I have created a string field (CSMText) in Account table. 

And there is a catalog item with select variable(Name- CSM). On load of form the value of CSMText should populate as a select box of the logged in user's account.

 

I have posted on more query related to this.

https://www.servicenow.com/community/now-platform-forum/add-remove-values-based-on-list-collector-in...

 

Thanks,

Sam

 

 

Hi @Samiksha2 

 

Might be helpful

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0779000

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Hi @Dr Atul G- LNG ,

 

This is to populate current user. How string will populate in select box?

 

Thanks,

Sam