- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi,
I'm trying to set a variable from g_modal using a UI Action. The goal is to set the value from the button to the variable, but this doesn't work. If I try to save it to any field, then it works properly.
Any thoughts on how to save the value to a variable?
UI Action (client)
function onClick(g_form) {
var fields = [{
type: 'choice',
name: 'reason',
label: getMessage('Choose reason'),
value: getMessage(' -- Select -- '),
choices: [{
displayValue: 'Missing details',
value: 'missing_details'
},
{
displayValue: 'Urgent issue',
value: 'urgent_issue'
}],
mandatory: true
}];
g_modal.showFields({
title: "Select your reason",
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_form.setValue('variables.reason', fieldValues.updatedFields[0].value);
g_form.save();
});
}
Modal:
Variable editor: empty when reason is seleted
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
this approach will work
1) use GlideAjax in workspace client script and pass the record sysId and the variable value
2) then in script include query that table with sysId and update the variable like this
gr.variables.reason = 'your value';
gr.update():
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
it should work with this, I added setWorkflow(false) in case some Query BR is stopping HR Case from being visible.
processReason: function() {
var sysId = this.getParameter('sysparm_sys_id');
var reason = this.getParameter('sysparm_reason');
var gr = new GlideRecord('sn_hr_core_case');
gr.addQuery('sys_id', sysId);
gr.setWorkflow(false);
gr.query();
if (gr.next()) {
gr.variables.reason = reason;
gr.update();
return 'success';
} else {
return 'Unable to update';
}
},
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar it seems like scope cross access is preventing the variable update, Script include and UI Action is in scope app. I need to check if creating a Cross scope privilege solves this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
yes that's the issue or else it should work fine.
Your UI action and Script Include should be in HR Core Scope only
Script Include should be made Accessible From All Scopes then only GlideAjax works from workspace client script
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskareven though I've moved the scripts to the HR scope, the variable is still not getting updated.
I've checked the Question Answer table and noticed that the value updates for a moment, then disappears.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
should not happen unless there is some other script which is clearing.
I believe I provided correct approach to use GlideAjax and it's partially working and you can debug further from here.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
