
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 12:06 PM
I need to update multiple values in a table with values from a newly imported table. This is a one time fix so I'm trying with a fix script. When I run it, no values are updated but there are also no errors.
I imported the new vendor numbers into a table (u_updatecanadavendors) that has current vendor number and new vendor number. I just want to update the vendor_code in the existing talbe (ap_vendor) with the new vendor number where the current vendor numbers match. I can't do this with a transform map because it's the foreign key that is being updated.
Is there a better approach to this. It seems like it should be a simple request. I'm new-ish to SN and have more experience in SQL. I want something similar to an update table query where the tables are joined on foreign key of current vendor number.
var gr = new GlideRecord('u_updatecanadavendors');
gr.addQuery('u_erp','Canada');
gr.query();
while(gr.next()){
var vend = new GlideRecord('ap_vendor');
vend.addQuery('vendor_code','gr.u_vendor_number');
vend.query();
if(vend.next()){
vend.vendor_code = gr.u_new_vendor_number;
vend.update();
}
}
*Duplicate question worded differently and changed script.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 12:12 PM
check this line:
vend.addQuery('vendor_code','gr.u_vendor_number');
it should be
vend.addQuery('vendor_code',gr.u_vendor_number);
I can't confirm this will fix it yet cause I don't know the structure of those tables, but try that and see if it works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 12:16 PM
Good catch. But still no luck

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 12:19 PM
What are field types for the following fields
1)u_erp
2)u_vendor_number
4)u_new_vendor_number
5)vendor_code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 12:58 PM
Thank you Jonathan and Abhinay! You both pointed me in the right direction. I removed the quotes and then when checking the field types of both tables realized they had cleared the updated vendor table in the dev environment. Once I reloaded it, it worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-29-2021 11:11 AM
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('cmdb_ci_comm');
gr.addQuery(‘phone_number ‘’);//comm
gr.addQuery(‘u_carrier ‘’);//comm;
gr.addQuery(‘assigned_to’);//comm;
if( gr.next() ) {
gr.setValue('phone_number',current.phone_number);
gr.setValue('u_carrier',current.carrier);
gr.setValue('assigned_to',current.employee_id);
gr.update();
}
Its not updating one table to another table