Why can't I find (and query with) parent sys_id from a demand task?

johannaS
Tera Expert

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.  

 

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

@Ankur Bawiskar is correct... it may not be the only issue in your script, but you do not use the sys_id to query against the number field. Line 9 should be:

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 + '' );

 

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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: find_real_file.png

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).

 

@Ankur Bawiskar is correct... it may not be the only issue in your script, but you do not use the sys_id to query against the number field. Line 9 should be:

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 + '' );