- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 01:55 AM
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);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 03:19 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 02:46 AM
Hi Naveen,
I second Harsh's view, it causes performance issues on views and roles. And also, i think keeping code simpler should be also kept in mind while adding scripts to the system .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 02:20 AM
Hi Surya,
Thank you so much for the code, it's working fine..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 02:40 AM
Hello Naveen,
I am glad to hear it works for you. Can you mark this thread as answered. so others might be benefit for the future reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 02:02 AM
I need to autopopulate the assignment group field on form load
.. with what value?
I have wrtiten the below client script code.
... which is not a good approach. Client scripts should be considered the last approach, not the first.
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???
You've nailed it. Client scripts are notorious for breaking during upgrades. Instead, look at the following:
1. the field can have a default value placed in it - client scripts aren't necessary
2. Assignment Lookup Rules should be used for auto-assignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 02:13 AM
Hi Smith,
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. Can u please guide if u have any other way??
Thanks,
Naveen