Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

check to see if incident has incident task

sonita
Giga Guru

I need to check if the incident has incident task or not:

If the incident has an inc task, the incident state should stay the same & If the incident does not have an inc task, I need to change the incident state to new.

this is what I've done :

I should mention that 'u_inc' is a field in the inc task table and it has the corresponding incident.

var rec=new GlideRecord('incident');

rec.addQuery('assigned_to',current.sys_id);

//rec.addQuery('assigned_to.active',false);

rec.addQuery('active',true);  

rec.addQuery('state','!=',6);

rec.addQuery('state','!=',7);

rec.query();  

while(rec.next())

{

  rec.assigned_to = '';

    rec.work_notes = "This ticket has been reassigned to the group because the original assignee is no longer active.";

  rec.setWorkflow(false);  

  rec.autoSysFields(false);  

var grIncidentTask = new GlideRecord('u_inc_task');

grIncidentTask.addQuery('u_inc',current.sys_id);

grIncidentTask.query();

if(grIncidentTask.getRowCount() == 0 )//If the incident does not have an inc task

{

        rec.state = 1;//change the incident state to new

   

  gs.addInfoMessage('incident does not have an inc task');

}

  else if(grIncidentTask.getRowCount()!= 0 )//If the incident has an inc task

{

  //the incident state should stay the same

  gs.addInfoMessage('incident has an inc task');

}

  rec.update();  

}

MY problem:   no matter if the incident has inc task or not it changes the state to new!! and I get this msg! --> gs.addInfoMessage('incident does not have an inc task');

I need in situations that inc has inc task , the state should stay the same

1 ACCEPTED SOLUTION

david_legrand
Kilo Sage

Easy one



grIncidentTask.addQuery('u_inc',current.sys_id);



not current but rec I think


View solution in original post

5 REPLIES 5

yes, the current seems to be a "sys_user", right (it's a business rule on the sys_user table) and your rec seems to be your incidents