copy a string value to a reference field

Snow Dev5
Tera Contributor

Hi SNOW Dev,

Is it possible to assign a string value to a reference field? For example,assignment group is a reference field, and I'd like to assign "Team Acme" (String) to an assignment group field like the below.

 

assignment_group = "Team Acme"

 

I tried it but didn't work. Thank you in advance.

1 ACCEPTED SOLUTION

Dhananjay Pawar
Kilo Sage

Hi,

Check below script.

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010111');
gr.query();
while(gr.next()){
var str_value=gr.description;
gs.print(str_value);
gr.assignment_group.setDisplayValue(str_value);
gr.update();
}

 

Result -

find_real_file.png

 

Note - Make sure your string value should be present in Group table.

 

Mark correct/helpful based on impact.

Thanks,

Dhananjay.

View solution in original post

18 REPLIES 18

Reference field require sys_id or Display value. I can see you have used 'database' group so in that case the display value is "Database" with capital D.

Best way is to take the sys_id of Data base group and try like this.

gr.assignment_group = 'SYS ID HERE';

 

if you want to use Display name then try this.

gr.assignment_group = 'Database';

 

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

 

Regards,
Muhammad

Hi Sharjeel,

var gr = new GlideRecord ('incident');
gr.addEncodedQuery('numberSTARTSWITHINC0009009');
gr.query();

if (gr.get('287ee6fea9fe198100ada7950d0b1b73')){
//Database group sys_id


gr.assignment_group.setDisplayValue('Database');

gr.update();

}

Could you take a look? Once again, thank you!

 

 

Let's debug this. I have placed few logs lets run your fix script and see what you got in the logs. 

 

var gr = new GlideRecord ('incident');
gr.addEncodedQuery('number=INC0009009');
gr.setLimit(1); // return only one record. 
gr.query();

gs.info("SNOW DEV - " + gr.getRowCount());

if(gr.next()) {

 gs.info("SNOW DEV - " + "record Found!");
 gr.assignment_group.setDisplayValue('Database');
 gr.update();

}​

Select Proceed from the dialog box and share me the screenshot of logs you got once fix script executed completely.

find_real_file.png

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

Thank you!

find_real_file.png

Wow! Happy Learning Sir.

Regards,
Muhammad