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.

Business rule to set assigned to as logged in user -Scoped application

Mrman
Tera Guru

Hi All,

I am trying to set the assigned to of a HR case after submitting from create new case in HR case management.

below is the business rule created however it is not working in scoped application.

Before Insert 

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




    var Cusr = gs.getUserID();
	var Cag = current.assignment_group.getDisplayValue();
    if (Cusr.isMemberOf(Cag)){
        current.assigned_to = Cusr;
    }
1 ACCEPTED SOLUTION

You can use the script provide in your after-insert BR, and yes it follows best practice to use current.update() in after-insert Business rule.

Use the script below and it will work.

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

    var Cusr = gs.getUserID();
	//var Cop = current.opened_by;
	gs.info('the logged in user is :' +Cusr);
	var Cag = current.assignment_group.getDisplayValue();
	gs.info('the assignment group is :'+Cag);
    if (gs.getUser().isMemberOf(current.assignment_group.getDisplayValue())){
		gs.info('into my if loop');
        current.assigned_to = Cusr;
		current.update();
    }

})(current, previous);

View solution in original post

30 REPLIES 30

Alok Das
Tera Guru

Hi,

Try with below script.

function executeRule(current, previous /*null when async*/ ) {
	if(gs.getUser().isMemberOf(current.assignment_group.name.toString()))
		current.assigned_to=gs.getUserID();
}

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok

Hi@Alok Das ,

I tried script you provide but assigned is not getting populated.please suggest.

Could you please share the condition in when to apply section details? I believe the business rule is not getting triggered.

 

Also, try checking the update checkbox as true and use the provided script.