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

Ankur Bawiskar
Tera Patron
Tera Patron

@Samiksha2 

onCell edit can only access value of the field on which onCell edit runs.

So g_form cannot be used there.

For this you need to use before update BR with similar conditions and abort the update

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

	// Add your code here

	var ag = current.getValue('assignment_group');
	var as = current.getValue('assigned_to');
	if (current.state == 7 && ((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 ,

Thank you for you reply. But it is not working in the List.

 

Thanks,

Sam

@Samiksha2 

It should work provided your BR triggers with correct condition

what's the BR trigger condition?

It should be state changes to closed complete

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

Hi @Ankur Bawiskar ,

Please check the BR condition

Samiksha2_0-1696502719128.png