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 Autopopulate assignment group field??

naveenmyana
Giga Expert

Hi guys,

I need to autopopulate the assignment group field on form load, I have wrtiten the below client script code.

I am able to populate the group field, But going down the road If we upgrade the instance to higher version does it cause any effect...Please correct me I am going in the right way or not???

function onLoad() {

    //Type appropriate comment here, and begin script below

  var x = 'eecdfd9bff131100a0a5ffffffffffe9'; // sys_id of the group name

  g_form.setValue('assignment_group',x);

}

1 ACCEPTED SOLUTION

Hi Naveen,,



Although I am against the use of gliderecords on client script as earlier mentioned, indirectly you are hardcoding scripts which is even less reliable. But nevertheless in the code,please modify to


function onLoad() {


if(g_form.isNewRecord()){


  //Type appropriate comment here, and begin script below


  var gr = new GlideRecord('sys_user_group');


  gr.addQuery('name',"Facilities request assignment group");   //as per my experience group name changes later during the time.


  gr.query();


  if(gr.next()){


  g_form.setValue('assignment_group',gr.sys_id);


  }


}


}


View solution in original post

26 REPLIES 26

Just wondering if you can write a display BR?


Table: as required


advanced checked true



no need to check delete/query.



set field value in action tab to assignment group to your group.



condition in advanced tab current.isNewRecord()== true



I think this should work better.


rachelconstanti
Mega Sage

I am creating a Service Catalog Item with an assignment group variable and an assignment group manager variable.  

Can someone tell me how I can get the assignment group manager to auto-populate based on the assignment group using the default value - I really try to stay away from Client Scripts as we had many issues during our upgrade to Kingston.