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.

Populate catalog item field on submit

Community Alums
Not applicable

Hello, 

I'm trying to get a client script to work on the catalog but having no joy, anyone know where im going wrong? I want it to pick up which option the user has chosen and update the field based on that choice."

I seem to get "Error There is a JavaScript error in your browser console", I know it can work if I put a stand alone statement in like set a single value with no conditions but soon as I start adding in "if" conditions it doesnt like it.

function onSubmit() {
	var cr = g_form.getReference("role_required");
	var gr = g_form.getReference("current_role");
 var rq = g_form.getValue('request_needed_role_access');
	
	if (rq == add) {
		g_form.setValue("service_desk_info", "Add role: " + cr.u_role_ad_group);
	}else if
		(rq == remove) {
		g_form.setValue("service_desk_info", "Remove from AD Group: " + cr.u_role_ad_group);
	}else if
		(rq == amend) {
		g_form.setValue("service_desk_info", "Remove from AD Group: " + gr.u_role_ad_group + "Add to AD group: " + cr.u_role_ad_group);
			
	}
	
   
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

don't set value in onSubmit

Why not set value based on change of those 2 variables?

OR

Just set the other variable once RITM is submitted via workflow run script

var cr = current.variables.role_required.u_role_ad_group;
var gr = current.variables.current_role.u_role_ad_group;
var rq = current.variables.request_needed_role_access;

if (rq == 'add') {
	current.variables.service_desk_info =  "Add role: " + cr;
}else if(rq == 'remove') {
	current.variables.service_desk_info = "Remove from AD Group: " + cr;
}else if(rq == 'amend') {
	current.variables.service_desk_info = "Remove from AD Group: " + gr + "Add to AD group: " + cr;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

don't set value in onSubmit

Why not set value based on change of those 2 variables?

OR

Just set the other variable once RITM is submitted via workflow run script

var cr = current.variables.role_required.u_role_ad_group;
var gr = current.variables.current_role.u_role_ad_group;
var rq = current.variables.request_needed_role_access;

if (rq == 'add') {
	current.variables.service_desk_info =  "Add role: " + cr;
}else if(rq == 'remove') {
	current.variables.service_desk_info = "Remove from AD Group: " + cr;
}else if(rq == 'amend') {
	current.variables.service_desk_info = "Remove from AD Group: " + gr + "Add to AD group: " + cr;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Community Alums
Not applicable

Ankur, you've done it again! Cheers mate!

Glad to help.

Happy learning.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader