- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 10:04 PM
I've written a very long email script to display many fields on a task notification per the requestors preference. Problem is, I can't easily grab the sys_id out of a field like I have in the past from approvals. I'll add the relevant part of the script below along with the various fields that I've tried to add and configure to get the sys_id (I've tried adding a document id field to the task record, perhaps incorrectly) I would greatly appreciate any guidance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2022 06:38 AM
gr.addQuery( 'sys_id', current.getValue( 'parent' ) );
While current.parent will work in some cases, it is not universally coerced into a string value, so I always recommend being explicit and either "getting" the value or converting it to a string. The lines below should work equally well:
gr.addQuery( 'sys_id', current.parent.toString() );
gr.addQuery( 'sys_id', current.parent + '' );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2022 10:09 PM
Hi,
notification is on which table?
I believe you should be querying with sys_id and not number in line 9 if parent is reference
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2022 06:57 AM
The table is dmn_demand_task, the record that I need to retrieve the sys_id is on a custom demand child table. I do need to query with the sys_id. That's the issue I'm having. I don't know how to get the sys_id of the related records/parent demand. I was just trying different things when I took the screen shot. I tried querying a lot of different ways with sys_id. The problem is that I can't successfully save the parent records sys_id into a variable to put in the addQuery line and I can't seem to successfully get it using something like current.parent.sys_id. That's why I was trying to make a field on task that contains the sys_id. Something else I've tried that didn't work:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2022 02:39 AM
I do not completely understand your current problem - maybe you want to rephrase it so me and the community can help you better.
Just my observations from this thread so far (hopefully it helps you):
To get the sys_id of the parent you should be using current.getValue('parent'). This will return you a string or null (if no parent exists - just a theoretical case).
current.demand yields a value type GlideElement. On GlideElement you cannot use getValue (so e.g. current.parent.getValue('parent') would result in a crash at least in Scoped Applications).
On Scoped Applications, getValue only works on GlideRecords (current most likely is one).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2022 06:38 AM
gr.addQuery( 'sys_id', current.getValue( 'parent' ) );
While current.parent will work in some cases, it is not universally coerced into a string value, so I always recommend being explicit and either "getting" the value or converting it to a string. The lines below should work equally well:
gr.addQuery( 'sys_id', current.parent.toString() );
gr.addQuery( 'sys_id', current.parent + '' );