Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Make assigned to mandatory when state changes to Closed Complete in List view

Samiksha2
Mega Sage

Hi All,

 

I want to make assigned to mandatory when state changes to Closed Complete in List view.

I have created a client script onCellEdit. Field- state

I added the logic if State is Closed Complete and Assigned to or Assignment group is empty then it will not allow to save. 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;

    var ag = g_form.getValue('assignment_group');
    var as = g_form.getValue('assigned_to');
    if (newValue == 7 && ((ag == '') || (as == '')) {
            alert("Assignment group or Assigned to should not be empty")
            saveAndClose = false;
        } else {
            saveAndClose = true;
        }
        callback(saveAndClose);
    }

 

It is not working. Please help in this.

 

Thanks,

Samiksha

1 ACCEPTED SOLUTION

Martin Saeckel
Tera Expert

Hi Samiksha,

 

just for my understanding: do you want to have Assigned To mandatory so that it will block the row update in list view, when state changes to "Closed Complete"? In this case, you could consider a data policy. This should run on your task table for the condition that "State [is] Closed Complete". The data policy action would define "Assigned To" as mandatory[=]true.

If you use the data policy as UI policy as well, you with the same step apply your requirement to the form view.

 

Or did I get your request wrong?

 

Best regards

Martin

View solution in original post

14 REPLIES 14

@Samiksha2 

please share BR script

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

Hi @Ankur Bawiskar ,

Closed Complete state is 3 in task.

Samiksha2_0-1696503104787.png

 

Thanks,

Sam

@Samiksha2 

use this script

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var ag = current.getValue('assignment_group');
	var as = current.getValue('assigned_to');
	if (ag == '' || as == '') {
		gs.addErrorMessage("Assignment group or Assigned to should not be empty");
		current.setAbortAction(false);
	}

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar ,

Still I can closed complete the task if Assigned to is empty.😕

 

Thanks,

Sam

Hi @Ankur Bawiskar ,

I have deactivated BR and tried with Data policies(suggested by Martin. I guess it is working.

 

I am testing some more scenarios.