The CreatorCon Call for Content is officially open! Get started here.

g_scratchpad in Display Business Rule returns undefined

tomoldovan1
Giga Expert

I know I'm missing something simple here.

In time worked, trying to return task.parent.top_task.

Created a On-load Client Script:

alert(g_scratchpad.top);

Created a Business rule on Time Worked (task_time_worked)

var gr = new GlideRecord('pm_project_task')

gr.addQuery('sys_id', current.task);

gr.Query();

g_scratchpad.top = gr.top_task.getDisplayValue();

Result is undefined.   Even if put the current task in a variable, I still get undefined alert when I load the form.  

The form does have a PRJTASK in the task field, as the form is called via "New" button on the Project Task Time Worked related list.

var ta = current.task   //Time Worked Table

var gr = new GlideRecord('pm_project_task')

gr.addQuery('sys_id', ta);

gr.Query();

g_scratchpad.top = gr.top_task.getDisplayValue();

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,



You need to do a gr.next() to actually get to the specific record.When getting a single record, you can use get() like this to save a few lines since it does both query() and next() for you.



var gr = new GlideRecord('pm_project_task')


gr.get(current.task);


g_scratchpad.top = gr.top_task.getDisplayValue();



//Göran


View solution in original post

4 REPLIES 4

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,



You need to do a gr.next() to actually get to the specific record.When getting a single record, you can use get() like this to save a few lines since it does both query() and next() for you.



var gr = new GlideRecord('pm_project_task')


gr.get(current.task);


g_scratchpad.top = gr.top_task.getDisplayValue();



//Göran


Thanks Goran!


No problemo,



Just shout if you run into anything else.



//Göran


pawan k singh
Tera Guru

Had similar issue. In my case it was happened due to, Display Business rule was written on the different table and we were using g_scratchpad in different table. 

So after adding same Display Business rule for the table used in Client script resolved our issue.

Regards

Pawan K Singh