BR to copy a field to a referenced table

catia_alves
Tera Expert

I created a BR to copy a field value from a custom field in sysapproval_approver to another field in a custom table. For some reason when I query for the sys_id the BR does not work, only if I hard-code a sys_id.

After, Update BR, Order 100, table:  sysapproval_approver 

Field to be copied: u_ic_id2

Target table: u_it_investment_committee_request

Target field: u_ic_id 

*****************************************

(function executeRule(current, previous /* , g */ ) {
    var itInvestmentRequest = new GlideRecord('u_it_investment_committee_request');
    itInvestmentRequest.addQuery("sys_id", current.sys_id );
    itInvestmentRequest.query();
    if (itInvestmentRequest.next()) {
        itInvestmentRequest.u_ic_id = current.u_ic_id2;
        itInvestmentRequest.update();
    }
})(current, previous);

***********************************
I also tried  itInvestmentRequest.addQuery("sys_id", current.itInvestmentRequest.sys_id ); and other ways to get the sys_id but none of them worked.


Can anyone help, please?
Thank you a lot in advance.


1 ACCEPTED SOLUTION

catia_alves
Tera Expert

The solution was to use the document_id

itInvestmentRequest.addQuery("sys_id", current.document_id); 

View solution in original post

6 REPLIES 6

Harish Bainsla
Kilo Patron
Kilo Patron

I have made small change in your script please try

(function executeRule(current, previous /* , g */ ) {
var itInvestmentRequest = new GlideRecord('u_it_investment_committee_request');
itInvestmentRequest.addQuery("sys_id", current.u_it_investment_committee_request.sys_id); // Use the correct reference to sys_id
itInvestmentRequest.query();
if (itInvestmentRequest.next()) {
itInvestmentRequest.u_ic_id = current.u_ic_id2;
itInvestmentRequest.update();
}
})(current, previous);

Hi Harish,

 

It did not work either.
Thank you for your reply.

(function executeRule(current, previous /* , g */) {

var sourceValue = current.u_source_field; // Replace with your field name


var customTable = new GlideRecord('u_custom_table'); // Replace with your table name
customTable.addQuery('sys_id', current.u_custom_table_reference);
customTable.query();

if (customTable.next()) {
customTable.u_target_field = sourceValue;
customTable.update();
}
})(current, previous);

please put field name correct and table name

catia_alves
Tera Expert

The solution was to use the document_id

itInvestmentRequest.addQuery("sys_id", current.document_id);