Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

I hHelp with Catalog Client Script for loading Support Group for the CI

Wendy Peterson
Tera Guru

I have a Script that I need help with. I have this to load the CI Support group based on the that CI. But groups no longer want to get these for some. SO I have a value on the Group called u_no_generic_request and it's set to true for the group that don't want to get them. I am trying to have it look at that field if that is set to 'true' then don't autoload the support group but if it's 'false' then it can. This script though is saying they are all set to generic no matter what i pick. I know i have something wrong I am just not sure what. TIA

 

2025-04-22_13-35-15.jpg

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.setValue('support_group', '');
        return;
    }

    if (!g_form.getControl('support_group')) {
        return;
    }
    var group = g_form.getReference('support_group');
    if (group && group.u_no_generic_requests === false) {
        g_form.setValue('support_group', newValue);
    } else {
        g_form.clearValue('support_group');
        alert('The selected group does not accept Generic Service Requests and cannot be set as the support group.');
    }
}

 

 

1 ACCEPTED SOLUTION

Robert H
Mega Sage

Hello @Wendy Peterson ,

 

I understand you have a variable for selecting a CI and a variable for a Support group on your Catalog Item.

Which of these two variables is this onChange Script running on?

 

Assuming it's an onChange of the Support group variable, the script would need to look like this:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    g_form.getReference('support_group', group => {
        if (group && group.u_no_generic_requests === 'false') {
            g_form.clearValue('support_group');
            g_form.showErrorBox('support_group', 'The selected group does not accept Generic Service Requests and cannot be set as the support group.');
        }
    });

}

 

Regards,

Robert

View solution in original post

7 REPLIES 7

Robert H
Mega Sage

Hello @Wendy Peterson ,

 

I understand you have a variable for selecting a CI and a variable for a Support group on your Catalog Item.

Which of these two variables is this onChange Script running on?

 

Assuming it's an onChange of the Support group variable, the script would need to look like this:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    g_form.getReference('support_group', group => {
        if (group && group.u_no_generic_requests === 'false') {
            g_form.clearValue('support_group');
            g_form.showErrorBox('support_group', 'The selected group does not accept Generic Service Requests and cannot be set as the support group.');
        }
    });

}

 

Regards,

Robert

It's running on the Configuration Name Field (configuration_name) on change that goes the CI's and it's auto populating the Support Group (support_group) of the CI. But I don't want it to populate if that u_generic_service_requests is true. TIA

Screenshot 2025-04-22 at 13-58-33 Service Request ServiceNow DEV CLONED 3_15_25 - Xanadu P6.png

Hello @Wendy Peterson ,

 

Thanks for the clarification.

 

Please make your onChange script run on the Support group variable instead, and use the script I provided earlier (also pasting it again below).

 

And then please update the configuration of the Support group variable like this:

RobertH_0-1745348873106.png

 

This will take care of auto-populating the Support group based on the selected CI. No scripting required for that part.

So we only need the script on the Support group variable to check if that auto-populated group has "u_no_generic_requests" set to false.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    g_form.getReference('support_group', group => {
        if (group && group.u_no_generic_requests === 'false') {
            g_form.clearValue('support_group');
            g_form.showErrorBox('support_group', 'The selected group does not accept Generic Service Requests and cannot be set as the support group.');
        }
    });

}

 

Regards,

Robert 

This is what I originally had and this works. But It's not looking at the Support Group to see if that flag is set.

function onChange(control, oldValue, newValue, isLoading) {

  if (isLoading) {
    return;
  }
  if (newValue == '') {
    g_form.setValue('support_group', '');
    return;
  }

  if (!g_form.getControl('support_group')) {
    return;
  }
  var ci = g_form.getReference('configuration_name', setSupportGroup);
}

function setSupportGroup(ci) {
  if (ci) {
    g_form.setValue('support_group', ci.support_group);
  }
}