i need to check the catalog task state

chinna
Mega Guru

Hi team,

 

in the workflow i need to check the catalog task state.

the user is set to state 'delivered' in the catalog task , i want automatically update the catalog state as closed complete.

i have tried with the run script in the workflow activity with the below script

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');

gr.query();
while(gr.next()){
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}

but its not working for me.

can someone please help me with script.

 

Regards,

chinna

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

HI @chinna 

Please use the below modified script:

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state',8);
gr.query();
while(gr.next()){
gr.state = 3;
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}

Also if this does not works then can you run the below script in background and see what result are getting printed:

Navigate to Background Script module and execute below script and see what is getting printed for below script:

find_real_file.png

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state',8);
gr.query();
gs.info('Row Count' + gr.getRowCount());
while(gr.next()){
gr.state = 3;
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you sure the query for state = 8 is working fine and giving you records?

are you setting correct value for state 3

Regards
Ankur

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

Hi @Ankur Bawiskar   ,

thanks for the help in the workflow what exactly find_real_file.png

 

iIn the wait for condition am checking the state values with the below script

var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.getValue('sys_id'));
rec.addQuery('state','NOT IN','3,4,7');
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}

if the state values is "open,workin progress and closed skipped), i dont want to move the catalog task forward.

 

and then am checking the state ' delivery' in the run script and trying to set the values.

 

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');
gr.query();
gs.log('TaskCount' +gr.getRowCount());
gs.log('RITM Sysid' +current.getUniqueValue());
while(gr.next()){
gs.log('InsideWhile' +current.state);
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}

 

as you suggested i have tried with logs, but it returning (row count is :0).

 

can you please helpme what exactly i hav edone wrong here.

 

Regards,

Chinn

Hi @Ankur Bawiskar 

 

can you please help me with above requirement.

 

Thanks,

chinna

Prasad Pagar
Mega Sage

Hi @chinna 

Code seems fine. Try adding some logs to verify if its going inside while something like below

Also recheck what Ankur is saying.

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.getUniqueValue());
gr.addQuery('state', '8');
gr.query();
gs.log('TaskCount' +gr.getRowCount());
gs.log('RITM Sysid' +current.getUniqueValue());
while(gr.next()){
gs.log('InsideWhile' +current.state);
gr.setValue('state', '3');
gr.setWorkflow(false); //Set this value if you don't want any scripts to be triggered after the update
gr.update();
}

Check in logs table post that for these messages.

Thank you
Prasad