- 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
@Ankur Bawiskar sure, I’ll close this thread since you resolved the first issue with GlideAjax.
Thanks a lot.
