- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2022 12:25 AM
Hi all,
How to get list of roles belong to the user in drop down in catalog item?
Please suggest me the script include and catalog client script to achieve this requirement.
Thanks
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2022 12:54 AM
Hi
Please update your scripts as provided below:
Script Include: Just to remind
- Client Callable: true
- Script:
var yourScriptIncludeName = Class.create(); yourScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, { getStates: function() { var list = []; var userValue = this.getParameter('sysparm_val'); //Issue1: Table name was not in quotes var map = new GlideRecord('sys_user_has_role'); map.addQuery('user.sys_id', userValue); map.query(); while (map.next()) { var eObj = {}; eObj.name = map.role.name + ''; eObj.sys_id = map.getValue('role'); list.push(eObj); } } return JSON.stringify(list); }, type: 'yourScriptIncludeName' });
Client Script:
- Type: On Change
- Field/Variable: Field corresponding to req
- Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } //GlideAjax Call to fetch Roles for Requestor var ga = new GlideAjax('yourScriptIncludeName'); ga.addParam('sysparm_name', 'getStates'); ga.addParam('sysparm_val', newValue); ga.getXMLAnswer(stateCallback); } function stateCallback(answer) { alert('answer=' + answer); var i = 1; var objList = JSON.parse(answer); g_form.clearOptions('role'); for (var keys in objList) { g_form.addOption('role', objList.sys_id, objList.name); i++; } //Select the Last Option g_form.setValue('role', objList[i].sys_id, objList[i].name); }
Remark: Ensure the variable/field is of Type Choice.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-04-2022 08:14 AM
Hi
Any update on your issue?
Did my solution work for you?
If yes and if my answer helped you out then please mark my answer as correct/helpful, so that other community members facing similar issues might get help.
Thanks and regards,
Kartik