Glide record query to check the result value?

sukran
Mega Sage

After querying table gliderecord of RITM and related records of catalog task

want to check all records state field value is not open or work in progress..

 

if query return records state field is contains open or in progress then skip or if not then update the value worknotes in ritm 

example - RITM query returns ( 5 catalog task) and if 2 are closed and 3 are opened .. 

we need to query after ritm closed , then check all catalog tasks are closed or not .. if any one open then it should not take action,, here the condition checks and any one task closed it moves to next script and update

I cant able to mention if condition to check state doesnt not contains

 

var gr = new GlideRecord('sc_task');

gr.addQuery('request_item=c6c2fa38472e869c9a2e9f98436d437a');

gr.query();

while(gr.next()){

var name = gr.request_item;

 

if(  gr.state !=''1 || gr.state !='2') // opnen and work In progress

 

gs.print('yes');

 

var gr1 = new GlideRecord('sc_req_item');

 

gr1.addQuery('sys_id' , name);

 

gr1.query();

 

if(gr1.next()){

 

gr1.status='1';

 

gr1.update();

4 REPLIES 4

Kieran Anson
Kilo Patron

Hi Sukran,

To confirm the requirement - you're wanting to check if any sc_task records are active when the paren sc_req_item is closed? And if so, abort the closure?

 

Rather than querying for states, use the 'active' field. Example:

var scTaskGR = new GlideRecord('sc_task');
scTaskGR.addActiveQuery();
scTaskGR.addQuery('request_item' , current.getUniqueValue()); //Assuming this is a br running on sc_req_item
scTaskGR.setLimit(1); //We only want to check for a single record;
scTaskGR.query();
if(scTaskGR.hasNext()){
	current.setAbortAction(true);
}

If any way to check if condition after querying RITM table ? Bcoz we have to do more after checking task state condition 

What additional checks are you doing? That will help provide the optimised code.

AshishKM
Kilo Patron
Kilo Patron

Hi @sukran , 

Please share the complete script code.

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution