- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15 hours ago
Hello folks,
I need you help on this one - I have a record with some variables (coming out of a Record Producer) that I open in the ESC in the OOTB Form page/widget. I have defined server-side UI Actions to drive state transitions however I need to prevent one of these transitions if one of the variables is not filled in.
Since these are server-side UI actions I'm trying to do this via onSubmit client script. The issue is that in the table's onSubmit client script g_form.getValue('variable_name') does not work and variables cannot be accessed (works only in backend, not in the portal).
Another thing I tried is a catalog catalog client script, however here the g_form.getActionName() is always 'submit' and not the action name of the UI Action that triggered the submission.
I would appreciate any help/hints on how to make this work.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
15 hours ago
in your UI action as well in server side you can check the variable value
if(current.variables.variableName == ''){
gs.addErrorMessage('Variable is empty');
}
else{
// continue your logic
}
OR
You can hide the UI action itself on your table if variable is empty and show it only when it's populated
check this in UI action condition
current.variables.variableName != ''
💡 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
15 hours ago
try accessing the variable value using this syntax on normal onSubmit script on your table
g_form.getValue('variables.variableName');
💡 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
15 hours ago
in your UI action as well in server side you can check the variable value
if(current.variables.variableName == ''){
gs.addErrorMessage('Variable is empty');
}
else{
// continue your logic
}
OR
You can hide the UI action itself on your table if variable is empty and show it only when it's populated
check this in UI action condition
current.variables.variableName != ''
💡 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
10 hours ago
Thank you, @Ankur Bawiskar
This seems to work better even though there is one little strange thing
The UI Action is pretty simple
if (current.variables.comment == '') {
gs.addErrorMessage('Comment field cannot be empty!');
current.setAbortAction(true);
} else {
current.state = 3; //Completed
current.update();
}1. When the form loads with an empty variable and you fill in the text and click the UI Action => everything works, record gets updated with the new state
2. When the form loads with an empty variable and you click the UI Action => everything works as expected and an error message is presented, record is not saved. What happens next is strange => you fill in the variable (no form reloads in-between) and click the UI Action again => the error message appears again (even though variable is not empty) => you click the UI Action again (no form reloads, variable is still with initially filled in value) and the record is saved successfully.
