- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 12:44 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 04:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:31 PM
I don't think you can. You will probably need to write a script include that is called using GlideAjax from the client script. You can then use returned data however you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 01:38 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 04:45 AM
Hey Brent,
That works!!!
Thank you so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2017 01:57 PM
Hi Monika,
Like I said, this would probably be a good candidate to utilise GlideAjax to just return the required 'roles' field value. Probably worth considering if it is going to be heavily used. In the meantime, I am glad I could help .
Brent