Departent field is not populating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 10:40 AM
Hi,
Requested by details are in variable set, created department as seperate variable. i want to populate department based on requested by. i wrote script include and onload CS. i'm not getting where i did mistake. Please help me.
Script include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 10:59 AM
First of all, when you post your code, make sure to format it as code using the corresponding toolbar icon. Otherwise, your code is very difficult to read.
Secondly, there are lots of things that can go wrong in your code. You need to learn to debug your code. Have you done any debugging at all before reaching out to the Community?
Finally, the most obvious reason why your code doesn't work is that you are using the sys_id of the Requestor as the value for the Department reference in this line:
g_form.setValue('department1', req);
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 12:37 PM
Hello @Shaik22
Are you trying to autopopulate department on selection of requested by? -> Use onChange Client Script & Script Include
Or Are both requested by and department getting populated basis on current logged in user? -> onLoad CS & script include?
Seeing your code, it seems you have over-complicated the code. Instead, you can simply define your code and use. For example -
getDepartmentDetail: function() {
var userSysId = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userSysId)) {
var departmentSysId = userGR.department;
}
return departmentSysId;
}
It gives you sys_id of department field. If your variable is already referencing department table (reference type) and you call this function as deafult value, that can also help.
Similarly, you can use the same function as a reference qualifier to limit the selection (if possibility to select new department value.)
Hope it helps.
Regards,
Shubham