- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 04:23 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2021 03:13 AM
Hi
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 05:40 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 06:18 AM
I am getting this error.
Unable to find workflow version for 0f670c8e1b23fb00b80e86ae6e4bcb0f (user=7e7721e4dbc04910347766d4059619ed)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2021 06:28 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2021 05:23 AM
Hi
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2021 07:33 AM
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
Regards,
Shloke