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

Please try with the below code :

 

gr1.cwd_number.setDisplayValue(gr.number); 

 

Thanks!

Hello @Community Alums,

 

Please try with the below code :

 

gr1.cwd_number.setDisplayValue(gr.number); 

 

Thanks!

Prathamesh G
Kilo Sage
Kilo Sage

Hello @Community Alums,

 

Continued from my previous response, You can use below syntax:

 

gr1.cwd_number.setDisplayValue('number'); //Use the backend value of the variable

 

or 

 

gr1.cwd_number.setDisplayValue(current.number); 

 

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

No luck @Prathamesh G 

vipinmathew
Mega Guru

Hi @Community Alums ,

Could you please give me insight for below queries,

  • You have created After BR on which table? 
  • course_number field in x_infte_diversity_course_week_detail tableis referencing to which table ?
  • cwd_number field in x_infte_diversity_course_task_for_registered_user table is referencing to which table ?

 

Regards,

Vipin Mathew