Urgent: Need help- UI Macro should run based on Roles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 04:58 AM
Hello,
I have created a UI Macro: to add new options to a field and it is working fine for me. But when i am impersonating to other user with ITIL role it is not working.
If we add any value in Add Data field and click on Primary Button and save the form then the value will be added and we can see that value in New Values dropdown.
UI Macro script:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<a onclick='updateList()'>
<span
aria-label="${HTML:gs.getMessage('Update List Field Choices')}"
title="${gs.getMessage('Update List Field Choices')}"
alt="${gs.getMessage('Update List Field Choices')}"
>
<button type="button" class="btn btn-primary">Primary</button>
</span>
</a>
<script>
function updateList(){
var listfield = 'u_new_values';//replace with the name of your List field
var tablename = 'u_new_table';//replace with the name of the table you created the List field on
var choicetext = g_form.getValue('u_add_data');//replace with the name of your String field
var choiceGR = new GlideRecord('sys_choice');
//first check to make sure the choice doesn't already exist
choiceGR.addQuery('name', tablename);
choiceGR.addQuery('element', listfield);
choiceGR.addQuery('value', choicetext);
choiceGR.query();
if(choiceGR.next()){
alert('Choice already exists on List');
return;
}
else{
//choice not found so create a new one
choiceGR.initialize();
choiceGR.name = tablename;
choiceGR.element = listfield;
choiceGR.language = 'en';
choiceGR.label = choicetext;
choiceGR.value = choicetext;
choiceGR.insert();
alert('Choice added to List');
g_form.clearValue('u_add_data');//replace with the name of your String field
}
}
</script>
</j:jelly>
Regards
Yogesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 08:12 AM
Hi,
this line is not present in your UI macro
It seems the itil user is not able to insert new choices using GlideRecord
Can you check what comes in alert for bold
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<a onclick='updateList()'>
<span
aria-label="${HTML:gs.getMessage('Update List Field Choices')}"
title="${gs.getMessage('Update List Field Choices')}"
alt="${gs.getMessage('Update List Field Choices')}"
>
<button type="button" class="btn btn-primary">Primary</button>
</span>
</a>
<script>
function updateList(){
var listfield = 'u_new_values';//replace with the name of your List field
var tablename = 'u_new_table';//replace with the name of the table you created the List field on
var choicetext = g_form.getValue('u_add_data');//replace with the name of your String field
var choiceGR = new GlideRecord('sys_choice');
//first check to make sure the choice doesn't already exist
choiceGR.addQuery('name', tablename);
choiceGR.addQuery('element', listfield);
choiceGR.addQuery('value', choicetext);
choiceGR.query();
if(choiceGR.next()){
alert('Choice already exists on List');
return;
}
else{
//choice not found so create a new one
alert(choiceGr.canCreate());
alert(choiceGr.canWrite())
choiceGR.initialize();
choiceGR.name = tablename;
choiceGR.element = listfield;
choiceGR.language = 'en';
choiceGR.label = choicetext;
choiceGR.value = choicetext;
choiceGR.insert();
alert('Choice added to List');
g_form.clearValue('u_add_data');//replace with the name of your String field
}
}
</script>
</j:jelly>
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 08:46 AM
Hi Ankur,
after adding these 2 lines nothing is happening. I mean no alerts and the data is also not getting inserted.
alert(choiceGr.canCreate());
alert(choiceGr.canWrite());
Regards
Yogesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 08:12 PM
Hi,
not very sure then
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader