Script help - If the multiple persons are there in the Incident my script is not working

DNC
Tera Contributor
We are using the below script in the virtual agent to find, the logged in user is an Effected user / Caller / in watchlist of the Incident. If it is true it show that list.
 
(function execute() {
var incidents = new GlideAggregate('incident');
incidents.addEncodedQuery("stateIN1,2,3");
var qc = incidents.addQuery('caller_id', vaInputs.user);
qc.addOrCondition('u_affected_user', vaInputs.user);
qc.addOrCondition('watch_list', 'CONTAINS', vaInputs.user);
incidents.addAggregate('COUNT');
incidents.query();
var incidentCount = 0;
if (incidents.next()) {
incidentCount = incidents.getAggregate('COUNT');
}
vaVars.incident_count = incidentCount;
})()
 
The above script is not working when watchlist have more than one person then it is not recognizing the logged in user.
If only one person (Logged in user) in the watchlist it is showing the count.
find the screenshot of the field details.
NagarjunaD_0-1726753243087.png

 

Kindly help me.
 
Thanks
Nagarjuna
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It would be a better idea to combine the four query lines into one encoded query.  Manually filter an incident list view by this criteria with a sample user id until you see the expected records, then right-click the last breadcrumb in the filter and Copy query.  To make it work as an ecoded query you just need to replace the user sys_id breaking the encoded query string and  concatenating vaInputs.user.  You can test the query and count in a fix script hard-coding the user id if that's easier. 

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

It would be a better idea to combine the four query lines into one encoded query.  Manually filter an incident list view by this criteria with a sample user id until you see the expected records, then right-click the last breadcrumb in the filter and Copy query.  To make it work as an ecoded query you just need to replace the user sys_id breaking the encoded query string and  concatenating vaInputs.user.  You can test the query and count in a fix script hard-coding the user id if that's easier.