clear out field value

dev_K
Tera Contributor

Hi!

 

I would like to make sure that if user changes >>assignment group<< to a different one, the >>Assigned to<< field is cleared out. Like this we are sure that only ppl from the assignment group can be assigned to the task.

 

dev_K_0-1713519458219.png

Shall I use business rule to solve this?

 

thanks!

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @dev_K ,

I checked there is one OOB client script working on assignment group works on ONLOAD Firstly you can check your instance if this client script present or not, if not you can add that name "Empty assigned_to on group change"

You can create one client script and add below code 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading)
		return;

	// Need to get the form value, in case it changes but then changes back to value in database (oldValue is always DB value)
	if (oldValue != newValue)
		g_scratchpad.formValue = newValue;

	if (newValue === '' || newValue == null || oldValue != newValue || newValue != g_scratchpad.formValue) {
		if(newValue && g_form.getValue("assigned_to")){
			var groupLookupGr = new GlideRecord('sys_user_grmember');
			groupLookupGr.addQuery('group.sys_id', newValue);
			groupLookupGr.addQuery('user', g_form.getValue("assigned_to"));
			groupLookupGr.setLimit(1);
			groupLookupGr.query(groupLookupCallback);
		} else {
			g_form.setValue("assigned_to", "");
		}
	}
}

function groupLookupCallback(groupLookupGr){
	if (!groupLookupGr.hasNext())
		g_form.setValue("assigned_to", "");
}

 

 

Please refer below image 

SarthakKashya2_0-1713522800588.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak 

View solution in original post

8 REPLIES 8

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @dev_K 

It is OOTB available , i just tested. When i change the Assignment group, assigned to field get empty.

*************************************************************************************************************
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]

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

I tested as well, in my instance it is not case and just received an incident regarding this issue.

Hi @dev_K 

 

Then check is any configuration changes done , you can use the client script onchange.

*************************************************************************************************************
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]

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

dev_K_0-1713521157743.png

any ideas why this does not work? when i change the assignment group, the assigned to remains the same