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

Hi,

Nice explanation with additional details. That may be why they marked your response as Correct as you explained things a bit more.

To that end, in the while loop they should also get into the habit of using getters and setters there as well, just to be safe. Examples from their script:

gr.getValue('short_description');
gr.getValue('u_requested_for');

etc.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@johannaS 

Did you mistakenly marked other response as correct?

I provided the same solution as 1st response and same was confirmed by other person whose response you have marked as correct.

Would you mind marking my response as correct as my comment helped/worked for you?

Regards
Ankur

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