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.

Assignment group should be changed based on change of CI

Community Alums
Not applicable

Have a requirement 

I have to populate the assignment group (eg:- test group) when i select any of the CI (eg:-a or b or c)

If i change the CI back to "mackbook air" then the Assignment group and Assigned to should be replaced back.

Can any one please help on this with script.

3 REPLIES 3

Bert_c1
Kilo Patron

Please see:

Client scripts (servicenow.com)

for one way to do what you ask. I see an example in my instance with name "Set assignment fields from table". You seem to want to set a specific value for the assignment group. If so, the logic is simpler.

Community Alums
Not applicable

Hi

Can you share me the script please 

Bert_c1
Kilo Patron

Hi,

The client script I have is from the "Advanced Work Assignment" package. Screenshot is attached.

The script follows:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var ga = new GlideAjax('TableFieldCheckerAjax');
	ga.addParam('sysparm_name', 'tableHasField');
	ga.addParam('sysparm_table_name', newValue);
	ga.addParam('sysparm_field_name', 'assigned_to');
	ga.getXML(TableFieldCheckerResultParse, [],
			['assign_to_field', 'assigned_to', "Assigned to"]);

	ga = new GlideAjax('TableFieldCheckerAjax');
	ga.addParam('sysparm_name', 'tableHasField');
	ga.addParam('sysparm_table_name', newValue);
	ga.addParam('sysparm_field_name', 'assignment_group');
	ga.getXML(TableFieldCheckerResultParse, [],
			['assignment_group_field', 'assignment_group', "Assignment group"]);
	
	
	function TableFieldCheckerResultParse(response, fieldNames) {

		var answer = response.responseXML.documentElement.getAttribute("answer");
		var isFieldOnTable = (answer == "true"); // Ajax call returns string
		if (isFieldOnTable) {
			g_form.setValue(fieldNames[0], fieldNames[1], fieldNames[2]);
			var span = document.getElementById("sys_display.awa_service_channel."+fieldNames[0]);
			span.innerHTML = fieldNames[2];
		} else
			g_form.setValue(fieldNames[0], "");
	}
}

You will need the GlideAjax logic if you want to query the sys_user_group table for values.  if you know specific groups, you can use the 'g_form.setValue() method to set speficic values.