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.

How do you set the current user to the "Assigned To" field using Assignment rules?

warren_chan
ServiceNow Employee
ServiceNow Employee

I'm using an Assignment rule to populate the "Assignment group" field, and thought I could set the "Assigned to" field to be the current user while I'm at it. I thought this would be a simple statement, like:

 

current.assigned_to = gs.getUser();

 

but this doesn't seem to be working. I can get this working with a business rule (user as Dynamic Default of "Me"), but would prefer to use an Assignment rule instead. Any ideas?

 

Thanks!

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

If you are going to use a Script, I don't think you can have anything populated in the User or Group fields. If you do, I think it ignores the script.   Try blanking those two fields and use something like this for your script:



current.assigned_to = gs.getUserID();


current.assignment_group.name = 'Network';



Thanks!


View solution in original post

12 REPLIES 12

Is the user a member of the assignment group? Maybe a business rule is preventing the assignment to a user that is not a member of that group.


warren_chan
ServiceNow Employee
ServiceNow Employee

It's a baseline system, I didn't see any conflicting rules or anything like that.


randrews
Tera Guru

whenever i am trying to get something like this done.. my first thought is "where can i steal that code from".... incident has an "assign to me" button as a ui action...



if you look in it you will find the meat of the code is the line...



g_form.setValue('assigned_to', g_user.userID, userInfo.userName);



i would probably steal the whole function just to be safe but i suspect you can do it with just that one line.



--------------entire function



function assignMe() {


          var ga = new GlideAjax('SoloGroupMember'); // the Script Include object name


          ga.addParam('sysparm_name','lookupMember'); // the function on the server to call


          ga.addParam('sysparm_user', g_user.userID); // required information to perform lookup


          ga.getXMLAnswer(isSolo); // function to call when the server responds


         


          function isSolo(answer) {


                jslog("***** is solo answer: " + answer);


                if(answer) {


                      var userInfo = answer.evalJSON();


                      if (userInfo.groupID){


                            g_form.setValue('assignment_group', userInfo.groupID, userInfo.groupName);


                      }


                      g_form.setValue('assigned_to', g_user.userID, userInfo.userName);


                }


          }


}


Michael Fry1
Kilo Patron

If you are going to use a Script, I don't think you can have anything populated in the User or Group fields. If you do, I think it ignores the script.   Try blanking those two fields and use something like this for your script:



current.assigned_to = gs.getUserID();


current.assignment_group.name = 'Network';



Thanks!


Michael,



That seems to be correct. It won't take the mix and match of field and script.



Thanks!