How can we update reference field value on table using Glide Record?

Harshal Sonawa1
Kilo Guru
contractNumber = 'FSD1111';
gr.setValue('u_contract', contractNumber);
gr.update();
 
I m trying to update using setValue() but its not working
1 ACCEPTED SOLUTION

Hi @shloke04 ,

Thanks a lot for helping and having patience. Finally, I am able to resolve this.

ac.update() will not work for saving(updating) values in table for reference field.

ac.updateWithReferences(); is correct method for it.

 

View solution in original post

18 REPLIES 18

shloke04
Kilo Patron

Hi,

Reference Field holds only Sys Id and the value you are trying to set as per example shared is a String value which will not work here.

So you need to do something like below:

var contactNumber = 'SYSID';
current.setValue('FIELDNAME',contactNumber);

Now it entirely depend where are you writing this code in whether it is an After or a Before Business Rule or a Client side activity?

Please confirm to assist you further.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

I am getting this error.

Unable to find workflow version for 0f670c8e1b23fb00b80e86ae6e4bcb0f (user=7e7721e4dbc04910347766d4059619ed)

Hi,

Just providing one liner statement will not help you here. You need to explain or elaborate clearly where are you trying to write your script what is the requirement with screenshots and then only someone from community forum can help you out.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi @shloke04 ,

I have written background script, where I want to update reference field value. When ac.update() written inside while loop it does not update field, but when written outside of while loop its inserting record instead of updating

 

var facilityContract = 'FCON0004614';
var ac = new GlideRecord('xyz');
ac.addEncodedQuery('contract.number=' + facilityContract);
ac.query();

gs.info("query Count: " + ac.getRowCount());


while(ac.next()) {
    gs.info("before update: " + ac.asset.u_contract.getDisplayValue() +  "  serial number:" + ac.asset.serial_number);
 
    
    var sysIdContact = '035406911b24bc1057c6ff3ecc4bcb5b';
    ac.setValue('asset.u_contract',sysIdContact );

    ac.update();
    
}

Hi,

I have modified your script, please try the script as mentioned below in your background script editor:

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

    // Add your code here
    var facilityContract = 'FCON0004614';
    var ac = new GlideRecord('xyz');
    ac.addEncodedQuery('contract.number=' + facilityContract);
    ac.query();
    gs.info("query Count: " + ac.getRowCount());
    while (ac.next()) {
        gs.info("before update: " + ac.asset.u_contract.getDisplayValue() + "  serial number:" + ac.asset.serial_number);
        var sysIdContact = '035406911b24bc1057c6ff3ecc4bcb5b';
        ac.asset.u_contract = sysIdContact;
        ac.setWorkflow(false);
		ac.update();
    }

})(current, previous);

 

Also, if this does not works then please let me know here the Info message you have got after your line "ac.query()" and the info log which you have given after while statement to check what is getting printed.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke