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.

How Can I use onChange Client Script to set Assignment Group based on Application Support Group

WazzaJC
Tera Expert

How Can I use onChange Client Script to set Assignment Group based on Application Support Group

 

I would appreciate any help/guidance on how to achieve this, using a simple onChange Client Script please.

 

On my standard 'Incident' form, I have a custom field called Application Name (u_application_name) which is a Reference field to the standard Applications table. Each Application has an associated 'Support Group' assigned.

 

I would like the standard 'Assignment Group' (assignment_group) field on my Incident form, to be auto populated with the Support Group that is associated with the Application (u_application_name) eg. u_application_name.support_group

 

So when the 'Application' changes, the 'Assignment Group' value needs to change and always be based on the Support Group associated with the Application.

 

Please kindly help me with the Script to use in the onChange.

 

Please see attached screenshot - this is what I am trying but this script is not working - perhaps because Application Name and Assignment Group are both Reference fields, I am not sure where my script is wrong ?

 

Many thanks. Here is the script I am using:

 

 

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

    //Set Assignment Group for Applications based on Application Support Group

    g_form.getValue('u_application_name');

    g_form.setValue('assignment_group', 'u_application_name.support_group');
}

 

 

1 ACCEPTED SOLUTION

Ahmmed Ali
Giga Sage
Giga Sage

Hello @WazzaJC 

 

Write onchange client script on application name field and script as :

 

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

    //Set Assignment Group for Applications based on Application Support Group
g_form.getReference('u_application_name' , function(response){
		g_form.setValue('assignment_group' , response.support_group);
	});

}

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

2 REPLIES 2

Ahmmed Ali
Giga Sage
Giga Sage

Hello @WazzaJC 

 

Write onchange client script on application name field and script as :

 

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

    //Set Assignment Group for Applications based on Application Support Group
g_form.getReference('u_application_name' , function(response){
		g_form.setValue('assignment_group' , response.support_group);
	});

}

 

Thanks,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ahmmed,

 

This is excellent, works perfectly for me, I have it all up and running now! 🙂

 

Thanks very much and I greatly appreciate the quick response, much appreciated kind sir.