- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 08:55 PM
Hi All,
We are customizing the virtual agent topic for displaying the count of incident. So we have to get incidents which are updated additional comments within last 3days only. For this I tried one code but it fetching all the active incidents of caller but, I need incidents which are updated additional comments field within last 3days.
Code: This is oob script action utility code
Output: getting all the active incidents of caller
regards,
Pavan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:07 AM - edited 04-28-2024 10:11 AM
@Pavan Kumar28 I tried to replicate your issue on the Incident table,
ServiceNow does not allow filtering on journal fields directly from the list view. This is because journal fields are not stored in the same table as the record they are associated with. Instead, they are stored in a separate journal table (sys_journal_field), and each entry in a journal field is a separate record in this table.
Used a scripted filter to achieve the above use case,
1. Created a script include which holds the sys id of the incident as "Element ID"
2. Create a filter which pushes the incidents records accordingly on the list view.
Navigate to System Definition -> Filters -> Create New
For testing purpose, I have updated the filter and it considered "Updated on as Today", change your filter accordingly. In the below screenshot it, lists only the record which got updated today.
3. In Virtual agent, in the script action update as below,
Note: Encoded query line colon,
(function execute() {
// Setting the incident count
var incidents = new GlideAggregate('incident');
incidents.addEncodedQuery('sys_id=javascript: new GetUpdatedIncs().getIncidents()^sys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
//incidents.addQuery('active', true);
//incidents.addQuery('caller_id', vaInputs.user);
incidents.addAggregate('COUNT');
incidents.query();
var incidentCount = 0;
if(incidents.next())
incidentCount = incidents.getAggregate('COUNT');
vaVars.incident_count = incidentCount;
})()
Results : "Displays 2 recently updated incidents" (text has been modified)
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 10:07 AM - edited 04-28-2024 10:11 AM
@Pavan Kumar28 I tried to replicate your issue on the Incident table,
ServiceNow does not allow filtering on journal fields directly from the list view. This is because journal fields are not stored in the same table as the record they are associated with. Instead, they are stored in a separate journal table (sys_journal_field), and each entry in a journal field is a separate record in this table.
Used a scripted filter to achieve the above use case,
1. Created a script include which holds the sys id of the incident as "Element ID"
2. Create a filter which pushes the incidents records accordingly on the list view.
Navigate to System Definition -> Filters -> Create New
For testing purpose, I have updated the filter and it considered "Updated on as Today", change your filter accordingly. In the below screenshot it, lists only the record which got updated today.
3. In Virtual agent, in the script action update as below,
Note: Encoded query line colon,
(function execute() {
// Setting the incident count
var incidents = new GlideAggregate('incident');
incidents.addEncodedQuery('sys_id=javascript: new GetUpdatedIncs().getIncidents()^sys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
//incidents.addQuery('active', true);
//incidents.addQuery('caller_id', vaInputs.user);
incidents.addAggregate('COUNT');
incidents.query();
var incidentCount = 0;
if(incidents.next())
incidentCount = incidents.getAggregate('COUNT');
vaVars.incident_count = incidentCount;
})()
Results : "Displays 2 recently updated incidents" (text has been modified)
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 06:53 PM
Hi @Sujatha V M,
Thanks for your info, I just tried the entire script which you are shared but i am getting "You have no active incidents" even though I updated additional comments for few Incidents. Did I miss something, can you please look on this. Is my filter condition is correct ?. Attaching the snip for the same.
Script Includes:
Filter Conditions:
Note: Sys ID is javascript:new GetAdditionalCommentsUpdatedtickets().getIncidents();
Script Action:
Output:
Thanks and regards,
Pavan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 10:22 PM
Hi @Sujatha V M,
Thanks for your info, I just tried the entire script which you are shared but i am getting "You have no active incidents" even though I updated additional comments for few Incidents. Did I miss something, can you please look on this. Is my filter condition is correct ?. Attaching the snip for the same.
Script Includes:
Filter Conditions:
Note: Sys ID is javascript:new GetAdditionalCommentsUpdatedtickets().getIncidents();
Script Action:
Output:
Thanks and regards,
Pavan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 05:18 AM - edited 04-30-2024 05:20 AM
@Pavan Kumar28 Please rectify this line, &colon is the issue as it had reflected while copying.
sys_id=javascript: new GetUpdatedIncs().getIncidents()^sys_updated_onONToday@javascript: gs.beginningOfToday()@javascript: gs.endOfToday()
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.