- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 11:31 PM
Can help me @Vasantharajan N
As I need to auto populate Assignment Group based on the User Company in both Portal View and IT View.
As in Portal View the Assignment Group field will not be there on the form.
But in IT View the Assignment Group field will be there on the Incident form.
In the IT View I was able to populate the Assignment Group by using the below Script but when I used the same script on a Catalog Client Script it's not working.
Client Script:
var BU_ID;
var Caller;
Caller = g_form.getValue("caller_id");
var newUser = new GlideRecord('sys_user');
newUser.addQuery('sys_id', Caller); //Changed this to sys_id, as it's reference field.
newUser.query();
if (newUser.next()){
BU_ID = newUser.company;
}
var company = new GlideRecord('core_company');
company.addQuery("sys_id",BU_ID);
company.query();
if (company.next()){
var compName = company.name;
var BU = new GlideRecord('core_company');
BU.addQuery("name",compName);
BU.addQuery("customer", true);
BU.query();
if(BU.next()){
var service_desk = BU.u_service_desk;
g_form.setValue('assignment_group',service_desk);
g_form.setMandatory('assignment_group', true);
}
}
IT View:
Based on the User Affected BU the Owner Group and the associated Service Desk group is populating in the assignment group.
Service Portal View:
Assignment Group field will not be there
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 04:44 AM
@Arjun Reddy Yer - I assume your client script logic is correct and given this record producer script.
Note:
- As Sujatha mentioned, Not to use GlideRecord in client script and use GlideAjax
- You are querying core_company table twice which i felt is not correct. So please make the necessary change if required.
Please replace the variable names as per your record producer variable name.
var BU_ID;
var Caller;
Caller = current.variable.on_behalf_of_variable_name // Please replace the on behalf of user vairbale name
var newUser = new GlideRecord('sys_user');
newUser.addQuery('sys_id', Caller); //Changed this to sys_id, as it's reference field.
newUser.query();
if (newUser.next()) {
BU_ID = newUser.company;
}
var company = new GlideRecord('core_company');
company.addQuery("sys_id", BU_ID);
company.query();
if (company.next()) {
var compName = company.name;
var BU = new GlideRecord('core_company');
BU.addQuery("name", compName);
BU.addQuery("customer", true);
BU.query();
if (BU.next()) {
var service_desk = BU.u_service_desk;
//g_form.setValue('assignment_group', service_desk);
//g_form.setMandatory('assignment_group', true);
current.assignment_group = service_desk; // Set the value for the assignment group
}
}
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 12:37 AM
Did you try Auto populate feature for Portal side?
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 12:48 AM
Have you done the mapping of "Affected BU" on the record producer variable or via script?
1. Via Script on the record producer
For eg, Mapping of short description from record producer to incident form.
2. Variable mapping to the field
If you can done this, then onChange of Affected BU using the client script on the incident table you can auto-populate the values of assignment group.
Note: Its not a best practice to use "GlideRecord" on client scripts. Use GlideAjax to access the details and set it on the form accordingly.
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2024 04:44 AM
@Arjun Reddy Yer - I assume your client script logic is correct and given this record producer script.
Note:
- As Sujatha mentioned, Not to use GlideRecord in client script and use GlideAjax
- You are querying core_company table twice which i felt is not correct. So please make the necessary change if required.
Please replace the variable names as per your record producer variable name.
var BU_ID;
var Caller;
Caller = current.variable.on_behalf_of_variable_name // Please replace the on behalf of user vairbale name
var newUser = new GlideRecord('sys_user');
newUser.addQuery('sys_id', Caller); //Changed this to sys_id, as it's reference field.
newUser.query();
if (newUser.next()) {
BU_ID = newUser.company;
}
var company = new GlideRecord('core_company');
company.addQuery("sys_id", BU_ID);
company.query();
if (company.next()) {
var compName = company.name;
var BU = new GlideRecord('core_company');
BU.addQuery("name", compName);
BU.addQuery("customer", true);
BU.query();
if (BU.next()) {
var service_desk = BU.u_service_desk;
//g_form.setValue('assignment_group', service_desk);
//g_form.setMandatory('assignment_group', true);
current.assignment_group = service_desk; // Set the value for the assignment group
}
}
Thanks & Regards,
Vasanth