Query of Reference field

eqassem
Kilo Explorer

Hi,

I am trying to create a client UI script in a module that activates on change of a list choice field.
The script should query a separate table on it's Reference field that matches the current tables "Number" Field and check the State field of those records..

So my script does the following using Glide and Javascript:


var rca = g_form.getValue('number');

var gr = new GlideRecord("u_lta");
gr.addQuery("u_parent_rca", rca);

//gr.addQuery('state', '=','3');
//gr.setQueryReferences(false);

gr.query();
while(gr.next()){
if(l==0){ msg += gr.number + " (" + gr.u_parent_rca + ")";}
msg += ",\n" + gr.number + " (" + gr.u_parent_rca + ")";
}

var answer = alert("There are Open Long Term Actions. Resolve remaining items:" + msg);
g_form.setValue("state",'1');


I commented out the State query part as I am not getting any records back.

I also tried using the setQueryReferences to false so that I can get the text of related fields queried instead of the actual link, but that seems to not be supported as I get an error message.

Any Ideas how I can get this to actually query the "u_parent_rca" reference field as a string or number and actually come back with results?

Thanks,

-Emran
2 REPLIES 2

eqassem
Kilo Explorer

I have an application, with two modules.
The first module is called RCA, the second is called LTA.
RCA is based off of task table and so is LTA.
RCA is the Parent ticket, which has multiple child LTA tickets.

I want to make a script that does not let the Parent ticket go to a State of Closed if it has Active child LTA tickets.

LTA is associated to RCA through a Relational List such that LTA's "Parent RCA" field is related to RCA's "Number" field.
I tried to do this by querying the LTA's "Parent RCA" reference field using a Client Side Script running off of "onChange" in the RCA Module. The query would look for LTA records containing "Parent RCA" reference fields containing the RCA "Number" field that is current.

Now, what the problem is, when I query the LTA table on it's "Parent RCA" reference field, I don't get any results back.



gr.addQuery("u_parent_rca", rca);
gr.query();

I tried doing an open query without any addQuery and look at what the value of the "Parent RCA" is:


gr.query();
gr.next();
alert(gr.u_parent_rca);

It returns a long text number field: 7b7e58c86dbb2c00604c773573c80571

I am assuming this is like a reference and there must be some other way to query the reference field, either by being able to specify a reference that matches that, or having the query work in a different way to query the value instead of the actual reference.
This command looked promising (in the glide document):


gr.setQueryReferences(false);

But it would give me an error saying it doesn't exist.

Please Help....

Thanks,

-Emran


I know this is an old post but I think I know why this is happening and I don't see that anyone responded.   Basically, you're getting an error because this function is not allowed within a scoped application.   I'm assuming you have a custom application you're working in.   See this link in the documentation regarding this. There is a note about it just a little bit down on the page.


Cheers!


Todd



GlideRecord - ServiceNow Wiki