Copying string field value into reference field

Community Alums
Not applicable

Hi There,

 

Greetings!!!

 

I am copying records from Table A to Table B on condition If field of Table C is set to "Selected"

I have a requirement to copy string value "Number" which is on Table A to reference field "CWD Number" on Table B

I have written a business rule, it's copying the task from Table A to Table B but not copying the Number to CWD Number:

 

Business Rule:

Tejas12_0-1703670376463.png

 

Tejas12_1-1703670400503.png

 

Script: 

(function executeRule(current, previous /*null when async*/ ) {

    var gr = new GlideRecord('x_infte_diversity_course_week_detail');
    gr.addQuery('course_number.sys_id', '535e228e478bfd1088119ac5536d43b7');
    gr.query();
    while (gr.next()) {
        var gr1 = new GlideRecord('x_infte_diversity_course_task_for_registered_user');
        gr1.initialize();
        var str_value = gr.number;
        //gs.info("The Number is :" +str_value);
        gr1.cwd_number.setDisplayValue(str_value);
        //gs.info("Number is :"+gr.number);
        //gr1.cwd_number = gr.number;
        //gr1.setDisplayValue("cwd_number", number);
        gr1.week_number = gr.week_number;
        gr1.description = gr.week_description;
        gr1.short_description = gr.agenda;
        gr1.insert();
    }
})(current, previous);
 
Note: It's not copying some of the fields.
19 REPLIES 19

Community Alums
Not applicable

Hi @Tai Vu ,

 

I tried both the ways - uniquevalue and sys_id, it's not working.

 

 

piyushsain
Tera Guru
Tera Guru

Hi ,

In line 11 try :  gr1.cwd_number = gr.getUniqueValue(); 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Community Alums
Not applicable

Hi @piyushsain ,

 

It's not working.

Prathamesh G
Kilo Sage
Kilo Sage
Hello @Community Alums ,
 
Please use the below syntax to set the reference field:
 
gr1.cwd_number.setDisplayValue('number');
 
It will definitely work for your case to set the reference field.
 
If the above answer resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.
 
Thank You!
Prathamesh.

Community Alums
Not applicable

Hi @Prathamesh G ,

 

It's not working.