- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 01:52 AM
We have Incident and Incident task associated for the Incident. We like to know how many (count) incidents and status of the task task assigned to parent Incident into a separate field called "Task Status & Count" in Incident form.
Incident Table :- Incident
Incident task Table :- u_incident_task
New field :- u_task_count_status
I tried with the below query BR on display but it is not working
Table : Incident
var inctask = new GlideRecord('u_incident_task');
inctask.addQuery('parent', current.sys_id);
inctask.addActiveQuery();
inctask.query();
if (inctask.next()) {
gs.addInfoMessage('Tasks : ' + inctask.getRowCount());
current.u_task_count_status = (sctask.getRowCount() + '-' + inctask.status);
}
}
Please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 03:04 AM
If thats your requirement, then you have to write an After BR on Incident task.
You are updating a field in Incident table on the basis of the incident task.
So when any new incident task gets created - query the Parent field of Incident task and get the corresponding Incident sys_id
And make the update on the Incident table's field task count status field
BR on incident task table
Insert and Update
Condition = current.active.changes()
Script -
var grInc = new GlideRecord('incident');
if(grInc.get(current.parent)){
if(current.active){
//default task count status to zero
//if any new incident task is created, then count increase
grInc.u_task_count_status = grInc.u_task_count_status + 1;
}
else{
//if the incident task is closed, then count decrease active tasks
grInc.u_task_count_status = grInc.u_task_count_status - 1;
}
}
Hopefully this helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 02:18 AM
Hi Venkat,
sctask.getRowCount() should be inctask.getRowCount() +
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 02:21 AM
This code will get all the active incident tasks associated to the incident -
var inctask = new GlideRecord('u_incident_task');
inctask.addQuery('parent', current.sys_id);
inctask.addActiveQuery();
inctask.query();
inctask variable will have records of incident task
When you write inctask.next() - it just means you are accessing the first record in the result
and you are storing that incident task status in the incident taskcount status field
Is that what you wanted to do?
And you have mentioned it is a display BR, the display BR is used to store value of server side field in sctrachpad variable
Could you please let us know in example what you want to see in Task Count Status field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 02:46 AM
Thanks Srikanth,
i need something like below in Task Count field
if incident INC0001111 has 2 Incident task then in my task count field it should have "Incident Task count is 2 - INCTASK1 is Open - INCTASK2 is Closed" like this .
is it possible?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2016 02:54 AM
Hi Teju,
This is not my requirement i need to have Task count number only the count in task count status field (status of the Incident task should be Open)