
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:21 AM
Hello
I would like to run a fix script to set a value of a field to the same as another field.
On the task table I have a field "Case's Vendor", and where this is "--None"" , I would like to force the value to be the same as the field "Asset's Vendor". (Which is a field in the cmdb_ci table) .
Here is my idea.
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("cmdb_ci.u_asset_s_vendor!=");
grTask.query();
while (grTask.next()) {
var assetVendor = g_form.getValue('cmdb_ci.u_asset_s_vendor');
grTask.u_case_s_vendor = assetVendor;
grTask.update();
}
Do you think it can work ?
Thanks
Jérôme
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:26 AM
g_form doesn't work in fix scripts:
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("cmdb_ci.u_asset_s_vendor!=");
grTask.query();
while (grTask.next()) {
var assetVendor = grTask.cmdb_ci.u_asset_s_vendor;
grTask.u_case_s_vendor = assetVendor;
grTask.update();
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:26 AM
g_form doesn't work in fix scripts:
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("cmdb_ci.u_asset_s_vendor!=");
grTask.query();
while (grTask.next()) {
var assetVendor = grTask.cmdb_ci.u_asset_s_vendor;
grTask.u_case_s_vendor = assetVendor;
grTask.update();
}
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:27 AM
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("cmdb_ci.u_asset_s_vendor!=");
grTask.query();
while (grTask.next()) {
var assetVendor = grTask.cmdb_ci.u_asset_s_vendor;
grTask.u_case_s_vendor = assetVendor;
grTask.update();
}
Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:38 AM
Hi,
your query is wrong; ensure you give correct query
Sharing my inputs
1) use a function to wrap the code
2) use try catch block to handle the exception
3) use setWorkflow(false) to avoid any BR from triggering on update if you wish for faster update
updateRecords();
function updateRecords(){
try{
var grTask = new GlideRecord("task");
grTask.addEncodedQuery("u_asset_s_vendorISEMPTY"); // give correct query based on what value --None-- has
grTask.query();
while (grTask.next()) {
var assetVendor = grTask.cmdb_ci.u_asset_s_vendor;
grTask.u_case_s_vendor = assetVendor;
grTask.setWorkflow(false);
grTask.update();
}
}
catch(ex){
gs.info(ex);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader