Get value of "User role" type field

monika94
Kilo Guru

Hi All,

Quick question. How can I get value of Roles field (type is-User Role) on sc_cat_item table using client script. getValue() returns nothing.

Thank you.

Monika

1 ACCEPTED SOLUTION

Brent Sutton
Mega Sage

Hi Monika,



If the the client script is being run on the sc_cat_item form then you could use the following code to return the comma separated list of roles in the user_role field (I've got it as an onLoad script but you can utilise it as required): -



function onLoad() {


    //Type appropriate comment here, and begin script below



        var sysID = g_form.getUniqueValue();


        var table = g_form.getTableName();



        var gr = new GlideRecord(table);



        if(gr.get(sysID)){


                  var roles = gr.getValue('roles');


                  g_form.addInfoMessage('Roles: ' + roles);


        }


}



This may be a good candidate for GlideAjax if you want the users to be able to continue while this query is being processed. All depends on your use case.



Hope this helps.


View solution in original post

10 REPLIES 10

Prateek kumar
Mega Sage

Hello Monika


This article will help you


https://www.servicenowguru.com/scripting/user-object-cheat-sheet/



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

monika94
Kilo Guru

Hello Prateek



Thank you for response. But I am trying to get value of field whose type is "USER ROLE".


HugoFirst
Kilo Sage

Hello Monika,



It would help to see the exact code that you are using.


Something like the following should work:



g_form.getValue('roles');


HV1
Mega Guru

Client script is on which table? can you share the screenshot of script?