Need to auto populate assignment group field on the Incident Form based on User Company

Arjun Reddy Yer
Tera Guru

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.

ArjunReddyYer_0-1712298433302.png

Service Portal View:

Assignment Group field will not be there 

ArjunReddyYer_1-1712298606476.png

 

1 ACCEPTED SOLUTION

Vasantharajan N
Giga Sage
Giga Sage

@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

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Arjun Reddy Yer 

 

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]

****************************************************************************************************************

Sujatha V M
Kilo Patron
Kilo Patron

@Arjun Reddy Yer  

 

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. 

 

SujathaVM_0-1712303004792.png

 

2. Variable mapping to the field

 

SujathaVM_1-1712303071719.png

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.

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Vasantharajan N
Giga Sage
Giga Sage

@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