issue with Background

Srini19
Tera Contributor

Hi,

 

I am trying to update the assignment group of problem record through BG but it is not happening. can you please advise what  could be the reason?

 

 

var gr=new GlideRecord('problem');
gr.addEncodedQuery('state=102');
gr.query();
gs.print(gr.getRowCount());
while(gr.next())
{
gr.assignment_group.name='Application Development';
gr.update();
}

 

Thanks

Srini

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Srini19 Assignment group is a reference field, you need to provide the sys_id of Application Development group, in order for the script to work.

 

 

var gr=new GlideRecord('problem');
gr.addEncodedQuery('state=102');
gr.query();
gs.print(gr.getRowCount());
while(gr.next())
{
gr.assignment_group= '<sys_id of Application Development group>';
gr.update();
}

 

 

Hope this helps.

 

SN_Learn
Kilo Patron
Kilo Patron

Hi @Srini19 ,

 

The assignment group is reference type field so we need to pass sysId of group instead of name

 

Please test the below:

var prbGr = new GlideRecord('problem');
prbGr.addEncodedQuery("state=102");
prbGr.query();
while(prbGr.next()){
	prbGr.setValue('assignment_group', '0a52d3dcd7011200f2d224837e6103f2'); //Replace with 'Application Development' group sysId
	prbGr.update();
}

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Manikanta Kota
Mega Guru

Hi @Srini19 ,

 

For Reference field Data come from another table you can use the Sys_id of that record .

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

 

regards,

Manikanta. Kota

Community Alums
Not applicable

Hi @Srini19 ,

You can't directly set the name of a reference field like this. Instead, you need to set the reference to the sys_id of the assignment group

 

Try with the below code,

var gr = new GlideRecord('problem');
gr.addEncodedQuery('state=102');
gr.query();
gs.print(gr.getRowCount());

var agGr = new GlideRecord('sys_user_group');
agGr.addQuery('name', 'Application Development');
agGr.query();
if (agGr.next()) {
    var agSysId = agGr.sys_id;
    
    while (gr.next()) {
        gr.assignment_group = agSysId;
        gr.update();
        gs.print("Updated problem: " + gr.number);
    }
} else {
    gs.print("Assignment group 'Application Development' not found");
}

 

 

If this is helpful please mark my response.

 

Thanks

Sravani