How to get last update from History Walker API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2023 05:38 AM
Hello All,
I got a requirement where I need to populate list of tasks 'assigned to' user under a custom module when the tasks are updated other than by 'Assigned To' user.
I have written the below script Include and calling from Module.
Here the issue I'm facing is, it's considering all the updates in the history and pushing the task under module even though current update doesn't satisfy the condition.
So we need to populate the tasks when the current update matches the condition in if conditions.
Issue ex:
In the script below if conditions is checking,
if (previousStatus == -3 && taskStatus== -2) { // In Progress (-2), pending(-3) condition
In the first update if any user other than assignee update task matching with the if case it will populate the task under list and when 'Assigned to' user updates the record the records will get dis appears from the list (this is expected) and when ever any other user other than assignee updates the task state without matching the if condition then also it's getting added to the list.(I assume this is because of matching condition in the first update, please suggest a way to push the record only when the current matches the condition).
Script Include:
getTaskUpdated: function(taskCount) {
var taskList = [];
var tCount = taskCount || 40;
var sysID = gs.getUserID(); // sys_id of the current LoggedIn user
var userName = gs.getUserName(); // EmailID of the current LoggedIn user
// Fetch the last logout time of the current loggedIN user
var user = new GlideRecord("sys_user");
var query = "active=true^assigned_to=" + sysID + "^sys_updated_by!=" + userName;
var eshTask = new GlideRecord("x_audit_task");
eshTask.addEncodedQuery(query);
eshTask.setLimit(tCount);
eshTask.query();
while (eshTask.next()) {
var hw = new sn_hw.HistoryWalker(eshTask.getTableName(), eshTask.getUniqueValue());
hw.setWithJournalFields(true);
for (var i = eshTask.sys_mod_count; i >= 0; i--) {
if (hw.walkTo(i)) {
var additionalComments = hw.getWalkedRecord().comments;
var taskStatus = hw.getWalkedRecord().status;
var workNotes = hw.getWalkedRecord().work_notes;
var previousStatus = hw.getWalkedRecord().previous_status; // custom field which stores the last/previous status of the record
if (previousStatus == -3 && taskStatus== -2) { // In Progress (-2), pending(-3)
taskList.push(eshTask.getDisplayValue());
break;
}
if (!gs.nil(additionalComments)) {
taskList.push(eshTask.getDisplayValue());
break;
}
if (!gs.nil(workNotes)) {
taskList.push(eshTask.getDisplayValue());
break;
}
}
}
}
return taskList.toString();
}