search for requested for

Jim Sheldon
Tera Contributor

Trying to find all requests for a specified user. Then creating tasks based on those requests.  Getting error 

Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "requested_for" from null
   script : Line(4) column(0)
      1: var applications = [];
      2: 
      3: var gr = new GlideRecord('sc_req_item'); //Indicate the table to query from
==>   4: gr.addQuery('Request.Requested_for', current.requested_for);
      5: gr.query(); //Execute the query
      6: while (gr.next()) {
      7:     applications.push(gr.short_description.toString());

 running script the first part is below

var applications = [];

var gr = new GlideRecord('sc_req_item'); //Indicate the table to query from
gr.addQuery('Request.Requested_for', current.requested_for);
gr.query(); //Execute the query
while (gr.next()) {
applications.push(gr.short_description.toString());
}

var applicationAA = [];
var applicationSS = [];
var applicationBI = [];
var applicationAB = [];
var applicationCA = [];

for (var i = 0; i < applications.length; i++) {
if (applications[i] == 'APCC Access'

 

what are we missing?

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

You'd probably need to adjust line such as:

 

gr.addQuery('requested_for', current.requested_for);

otherwise, if you're trying to look at the Request level then use:

gr.addQuery('request.requested_for', current.request.requested_for);

 

 


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

Jim Sheldon
Tera Contributor

same error

Hello,

Please ensure that your "current" object...has a "requested_for" field on it that you can tap into.

We don't know where you're running this, if it's in a business rule or wherever, but it would need have a current object with a requested_for field.

 

Please share what you have as of now for your script?

 

For example, please verify that your requested_for field is on the table associated to the "current" object, like so:

AllenAndreas_0-1678309029768.png

AllenAndreas_1-1678309057141.png

This example is for the RITM table.

 

If not, adjust your script as needed...as otherwise your script should be working fine.


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

Nia McCash
Mega Sage
Mega Sage

I think the error is referring to

current.requested_for

not

gr.addQuery('Request.Requested_for'

 What is 'current' in this context?