- 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
I don't think you can set variable value using g_form in workspace client script
g_form.setValue() will work to set variable value in variable editor in native
💡 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 is there any way to update variable using workspace client script?
- 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 - last edited 3 weeks ago
Hi @Ankur Bawiskar
This approach works partially. I’m able to fetch the value from the client side and pass it to the Script Include.
The issue I’m facing is that I can’t set this value to a variable using
gr.variables.reason = 'my value';
gr.update():
The variable value is stored in the question_answer table, and with this approach, it doesn’t work also.
processReason: function() {
var sysId = this.getParameter('sysparm_sys_id');
var reason = this.getParameter('sysparm_reason');
var gr = new GlideRecord('sn_hr_core_case');
if (!gr.get(sysId)) {
return 'Record not found';
}
var qAnswer = new GlideRecord('question_answer');
qAnswer.addQuery('table_sys_id', sysId);
qAnswer.addQuery('question.name', 'reason');
qAnswer.query();
if (qAnswer.next()) {
qAnswer.value = reason;
qAnswer.update();
return 'success';
} else {
return 'error:Question answer not found';
}
},
Any idea what might be wrong here?
