Copy content from one column to another

Don11
Mega Expert

Hello,

I am attempting to create a metric script which will copy content from 2x columns.  The conditions would be if the row is empty do not copy read and copy the alter row.

Example:

Meeting CAB Final results
1234   1234
  2222 2222
5678   5678
9101   9101
4321   4321
  1116 1116
5732   5732

Thank you,

 

 

var now_GR = new GlideRecord('u_chg_cab_definition_view');

now_GR.addQuery();

now_GR.query();

var count = now_GR.getRowCount();

if (count > 0) {

   var allocation = 'met_cab_definition';

   while (now_GR.next()) {

      now_GR.u_allocation = 'chg_u_cab_meeting';

      now_GR.update();

   }

}

 

 

 

1 ACCEPTED SOLUTION

Adrian Ubeda
Mega Sage
Mega Sage

Hi Don,

This code will let you iterate over the entire table and update the final result field if meeting or cab it is not empty:

var now_GR = new GlideRecord('u_chg_cab_definition_view');
now_GR.query();

while(now_GR.next()) {
  if(now_GR.meeting != '') {
    now_GR.final_result = now_GR.meeting;
  }else{
    now_GR.final_result = now_GR.cab;
  }
  now_GR.update();
}

If it was helpful, please give positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

View solution in original post

4 REPLIES 4

Adrian Ubeda
Mega Sage
Mega Sage

Hi Don,

This code will let you iterate over the entire table and update the final result field if meeting or cab it is not empty:

var now_GR = new GlideRecord('u_chg_cab_definition_view');
now_GR.query();

while(now_GR.next()) {
  if(now_GR.meeting != '') {
    now_GR.final_result = now_GR.meeting;
  }else{
    now_GR.final_result = now_GR.cab;
  }
  now_GR.update();
}

If it was helpful, please give positive feedback.
Thanks,

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆

Many thanks for all your help, much appreciated

Abhijit4
Mega Sage

What if both columns will have values? or this scenario is not possible?

What if both columns will have empty values, would you like to consider these 2 scenario as well in your script?

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hello Abhijit,

Thanks for your help!  Good question, I should have pointed this out from the beginning that a additional filter will be applied on column called "type=CAB" which will ensure each scenario would work perfectly.

 

So how would I modify your script to accommodate column filter "type=CAB"?

Thanks again

-Don