Changing dependent field value using Catalog client script

vidhya_mouli
Giga Sage

I have these variables on my catalog item:

vidhya_mouli_0-1702039452232.png

 

application_service is on cmdb_ci_service table.

support_group is on sys_user_group table

 

When application_service changes I want support_group to change automatically.

 

This is my catalog client script:

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

   var supportGroup = ''; 
    var cmdbCiService = new GlideRecord('cmdb_ci_service');
    cmdbCiService.addQuery('sys_id', newValue);
    cmdbCiService.query();

	g_form.addInfoMessage("OUSIDE: "+newValue);
	if (cmdbCiService.next()) {
		supportGroup = cmdbCiService.getValue('support_group');
        g_form.addInfoMessage("Support: " + supportGroup);
    }
	g_form.setValue("variables.support_group", supportGroup);
}

 

I am able to fetch the sys_id correctly but not able to set the value. How can I do this?

2 ACCEPTED SOLUTIONS

SANDEEP28
Mega Sage

@vidhya_mouli This can be done without scripting. Open the "Support group" variable and go to "Auto populate" section. 

 

In dependent question, select Application service and "Sys ID" in dot walk path field.

 

SANDEEP28_0-1702040324109.png

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

View solution in original post

Pavankumar_1
Mega Patron

Hi @vidhya_mouli ,

You don't need any scripting for this. Use the Auto populate option which is on your support group variable.

Select the dependent question as Application service and on Dot walk path select the Support group.

Refer below screen.

Screenshot 2023-12-08 at 6.38.14 PM.png

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

5 REPLIES 5

Hi @vidhya_mouli 

 

I missed out this question , but proud you accepted the right answer and OOTB. 

 

Thanks @Pavankumar_1 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************