Clear assigned to when assignment change

Deepanshi1
Mega Guru

Hi i make to assigned to field empty whenever assignment group changes. i tried onchange scritp, but its still not working.

5 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron
Tera Patron

Please share code snippet. 

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

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

View solution in original post

Jagadish Sanadi
Kilo Sage

Hello @Deepanshi1 

 

You can create before BR (apply on both form and list view) with insert/update with conditions are:

'Assigned to' is not empty AND 'Assignment group' changes AND 'Assignment group' is not empty

=> In the Actions tab, set 'Assigned to' to empty.

 

Please mark my answer helpful if I have answered you

View solution in original post

Sarika S Nair1
Kilo Sage

Hi @Deepanshi1 

use below script in onchange client script on field assignment group

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading) {
      return;
   }
if(newValue==''){
g_form.clearValue('assigned_to');
}

   //Type appropriate comment here, and begin script below
   
}

 

View solution in original post

Community Alums
Not applicable

Hi @Deepanshi1 

 

I've written a simple On-change client script & it seems to be working as per your requirement.

Please find the attached screenshot for your reference & below is the code which can be used to clear Assigned to when Assignment group changes.

 

Please mark it as Accepted if it worked for you or feel free to reply so that I can check it furthermore.

Madhansomesh_0-1707834053772.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(oldValue!=newValue)
	{
		g_form.clearValue('assigned_to');
	}
   //Type appropriate comment here, and begin script below

View solution in original post

AndersBGS
Tera Patron
Tera Patron

Hi @Deepanshi1 ,

 

Have you looked into the OOTB client script for incident table "Empty assigned_to on group change" which contains the onchange client script:

 

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", "");
}

This client scripts empties the assigned to based on the assignment group as you're requesting.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

5 REPLIES 5

AndersBGS
Tera Patron
Tera Patron

Hi @Deepanshi1 ,

 

Have you looked into the OOTB client script for incident table "Empty assigned_to on group change" which contains the onchange client script:

 

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", "");
}

This client scripts empties the assigned to based on the assignment group as you're requesting.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/