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

if you are hesitating to implement default value just because it's extended from task. then you can use dictionary override functionality


Thank you so much for your response, But the thing is this field is extended from task table, So i can't set a default value here.


Extending a table doesn't prevent a field holding a default value.


Can u please guide if u have any other way??


There are several ways:


  • use a Business Rule for all new inserts.
  • use Assignment Lookup Rules, as I'd already mentioned.
  • use dictionary overrides, as shown above - this is the recommended way
  • Scripting - which means ignoring all of the tools provided for you and reinventing the wheel yourself, then having to maintain code during updates/upgrades and causing developer frustration when others are trying to understand how this default behaviour occurs when there's nothing in Dictionary, Assignment rules or Business Rules that seems to be causing it.


In short, there are plenty of ways. Scripting should ALWAYS be considered a last resort when you've exhausted all other possibilities.


Hi Smith,



Well now I Have opted to set the default value byy using dictionary override, Please see my screenshot.


Could you please confirm if this will fix my problem without any issues when upgradation...



qwqwe.PNG


yes it will not make any issue at upgrade time .


Thanks, Harsh