- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 11:58 AM
Hello team,
I created a Catalog Item form that users can request to activate or deactivate a group, form is completed and the flow is also working fine.
the variable type is Reference, like the image below:
Depending of user selection (Re-Activate or Deactivate) the requirement is to show an error message below field "Name_of_the_Group":
"This group is already activated" or "This group is already deactivated".
I'm struggling to find a way to make this happen, my scripting is beginner...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 12:19 PM - edited 05-13-2024 12:22 PM
On a server script you could just 'dot-walk' to the active field on the sys_user_group table and test this against the deactivate/re-activate variable value. In an onChange Catalog Client Script you can do this using Glide Ajax:
or, since this is a simple case, getReference:
Both of these are excellent tools to have in your belt, so give them a try sometime. In this case, you could also use the newer (Utah) Variable Auto-Populate feature by creating a new variable to hold the active/inactive group value, then hide that variable on the form if you'd like. The advantage here is that your Catalog Client Script would just evaluate this variable's value against the deactivate/re-activate value, without the need for a server call and return in the script!
Let me know if you have questions on any of these approaches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:16 AM
You would most likely want to run this onChange of the t/f variable:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.hideFieldMsg('var_name'); //hide any previous messages
if (newValue == 'true') { //try without the quotes if it doesn't work
g_form.showFieldMsg('var_name','valid name','info', true);
}
if (newValue == 'false') {
g_form.showFieldMsg('var_name','invalid name','info', true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 08:48 AM
Your script is working fine for me, I forgot to mention that there is a selection before that (Deactivate or Re-Activate):
If the user select Deactivate and write a group name that the active status is False, the Show field msg will be
If the user select Re-Activate, and the group is already Active, the fieldmsg is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 11:05 AM
It sounds like you just need an AND condition in the IF statements:
if (newValue == 'false' && g_form.getValue('select_the_option_bellow') == 'DEACTIVATE') { //or whatever the actual value is
g_form.showFieldMsg('name_of_the_group_2','This group is already INACTIVE in Service Now','info', true);