- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 11:58 AM
Is it possible to write a GlideRecord query that will find records whose Parent reference is from a specific table? If not, could you search for records that have a parent then iterate over the results and match on the parent's table?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:24 PM
One more thought, if you want to force update your existing records without updating the Updated and Updated By fields as well as not force any notifications, etc you can use the below script instead:
var projRec = new GlideRecord("pm_project"); //
projRec.addQuery("parent.sys_class_name", "u_my_change");
projRec.query();
while(projRec.next()) {
projRec.u_change_parent = projRec.parent;
projRec.parent = "";
projRec.autoSysFields(false); // Do not update sys_updated_on, sys_updated_by, and sys_mod_count
projRec.setWorkflow(false); // Do not run any other business rules
projRec.update();
}
Please make sure you test this script in a test instance prior to production. You can even add a new line before liNe 3 such as projRec.addQuery("sys_id", "SYS_ID-OF-A-TEST-RECORD"); to test with one record.
You can put this code into a Fix Script and execute it from there.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:00 PM
Hello Bradley,
Can you provide some additional details on what you are trying to accomplish? Details are encouraged.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:00 PM
Hi Bradley,
If I understand correctly, the answer is yes. Can you provide an example so I can better understand what it is your are looking to do? Perhaps a use case with specifics?
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:03 PM
Hi Bradley,
You can write a GlideRecord query on Parent table. Please let us know your exact requirement.
You may find this help to start with: GlideRecord - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 12:11 PM
We are moving from Fuji to Istanbul. We had a workflow that is based on a custom table that extends [task]. For sake of example I'll call it [u_my_change]. That workflow creates a Project (pm_project) record that is a child of the custom table parent. There are significant code changes in the project area in Istanbul. On Fuji it was possible for project to have a parent of our table type. On Istanbul the parent must be a table that extends [planned_task]. If it is not ServiceNow fails silently when making calls to the new SNC.PlannedTaskAPI() library. This causes project calculations to not rollup and breaks our workflow.
SN have recommended that we add a separate parent reference which is of our custom table type, e.g, pm_project.u_change_parent.
I need to find all pm_project project records that have a parent that is of [u_my_change] and
(a) get the current pm_project.parent reference,
(b) copy it to pm_project.u_change_parent
(c) clear pm_project.parent
(d) possibly make other changes related to Istanbul project changes
(e) update the pm_project record.