- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2014 05:22 AM
I'm trying to save a change to database catalogs. For some reason, I cant get the change to "stick" after the script is run.
Here's my code. dbCatalogs is a GlideRecord built on the ci_rel_type table. It has been filtered down to have only database catalogs in the parent field.
while (dbCatalogs.next()) {
gs.log("Setting the environment for " + dbCatalogs.parent.name + " to " + dbCatalogs.child.used_for, progName);
dbCatalogs.parent.u_used_for = dbCatalogs.child.used_for;
//Turn off business rules/update recognition before saving
dbCatalogs.parent.autoSysFields(false);
dbCatalogs.parent.setWorkflow(false);
dbCatalogs.parent.update();
count++;
}
Do I have to make a GlideRecord on the database catalog tables, get the record based on the parent and then update that?
Sorry for the format; Im not sure how to paste in code format.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2014 05:32 AM
You can use the getRefRecord() method to load a GlideRecord of the parent field - GlideElement - ServiceNow Wiki
Your code should end up looking something like:
while (dbCatalogs.next()) {
gs.log("Setting the environment for " + dbCatalogs.parent.name + " to " + dbCatalogs.child.used_for, progName);
var parentGr = dbCatalogs.parent.getRefRecord();
parentGr.u_used_for = dbCatalogs.child.used_for;
//Turn off business rules/update recognition before saving
parentGr.autoSysFields(false);
parentGr.setWorkflow(false);
parentGr.update();
count++;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2014 05:32 AM
You can use the getRefRecord() method to load a GlideRecord of the parent field - GlideElement - ServiceNow Wiki
Your code should end up looking something like:
while (dbCatalogs.next()) {
gs.log("Setting the environment for " + dbCatalogs.parent.name + " to " + dbCatalogs.child.used_for, progName);
var parentGr = dbCatalogs.parent.getRefRecord();
parentGr.u_used_for = dbCatalogs.child.used_for;
//Turn off business rules/update recognition before saving
parentGr.autoSysFields(false);
parentGr.setWorkflow(false);
parentGr.update();
count++;
}