Copying string field value into reference field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 01:48 AM
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:
Script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 02:46 AM
Hi @vipinmathew ,
1) You have created After BR on which table?
Ans: It's third table "x_infte_diversity_super30_registration" on which condition is checked, if that is true
2) course_number field in x_infte_diversity_course_week_detail table is referencing to which table? -
Ans: No, There is a text field "Number" on "x_infte_diversity_course_week_detail" table which needs to be copied to cwd_number which is reference field on "x_infte_diversity_course_task_for_registered_user" table refering to "x_infte_diversity_course_week_detail" table
3) cwd_number field in x_infte_diversity_course_task_for_registered_user table is referencing to which table? Ans: refering to "x_infte_diversity_course_week_detail" table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 02:55 AM
Great @Community Alums ,
One more query ,
- '535e228e478bfd1088119ac5536d43b7' is of which record? Registration Record or Course Week record or Registered User ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 02:59 AM
It's an another reference field present on "x_infte_diversity_course_week_detail". That is being used to copy records belongs to that course.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 03:16 AM
Cool,
if cwd_number is refering to "x_infte_diversity_course_week_detail" table then why you want to set the NUMBER field value to cwd , Since you are querying the same table in the first glide record?.
var gr = new GlideRecord('x_infte_diversity_course_week_detail');
gr.addQuery('course_number.sys_id', '535e228e478bfd1088119ac5536d43b7');
gr.query();
gs.log(gr.getRowCount());
while (gr.next()) {
var gr1 = new GlideRecord('x_infte_diversity_course_task_for_registered_user');
gr1.initialize();
gr1.setValue('cwd_number',gr.getValue('sys_id'));
gr1.week_number = gr.week_number;
gr1.description = gr.week_description;
gr1.short_description = gr.agenda;
gr1.insert();
ps: make sure gr.getRowCount() is greater than ZERO
Please let me know your comments
Happy to Help 🙂
Regards,
Vipin Mathew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 08:14 PM
Please try to run your script in background/ fix script by setting some hardcoded values. check if it is working there.