- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi,
I'm creating a de-duplication template that use a script in the condition. The script create an array of sys_ids but it seems that the template is not using it and apply on all the de-duplicate tasks of the class instead of 20 I return in the script.
Could someone help identify what is wrong in this script?
In the gs.info, I see the result is correct, but when I run the template it takes all the tasks.
In the template, I've activated the check box "Automatically select all de-duplication tasks that match the selected class".
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I got the reason and solution;
- When the option "Automatically select all de-duplication tasks that match the selected class" is activated, all the active tasks of the class on which apply the template are associated (attribute "De-duplication Template" on the task).
- But only tasks that satisfy the condition or tasks in the array returned by the condition script are processed.
- The non-processed Tasks remains related with the template and thus unavailable to other templates.
- If later, the option "Automatically select all de-duplication tasks that match the selected class" is unchecked, the task already related to the template are not unrelated. If they are not closed, or have been reopened, they are reprocessed what ever is the condition. (this was my case)
If the option "Automatically select all de-duplication tasks that match the selected class" is not activated at the first run, only tasks that satisfy the condition are related to the template.
I've not found a way to dissociate a task from a template. I had to delete my tasks and run the CMDB Health Jobs to recreate the tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Amar,
Two separate things are working against you here, and both need fixing:
1. The condition script is evaluated once per de-duplication task, and it must return true or false for that task (the task being evaluated is available as current). Your script returns an array of sys_ids instead. A non-empty array is truthy, so every task passes the condition. That is why your gs.info output looks correct, the query itself works fine, but the template still picks up all tasks.
2. The "Automatically select all de-duplication tasks that match the selected class" checkbox selects every task of the class regardless of the condition script. With it enabled, the condition is effectively ignored. Uncheck it.
Rewrite the condition to test the task being evaluated, for example:
(function() {
return current.short_description == 'Duplicate records found in 1 class: Computer - XX';
})();
If you need to match a set of tasks rather than one description, check the current task against your list, for example return tskList.indexOf(current.getUniqueValue()) > -1, but do not return the list itself.
Fix both, then re-run the template and only the matching tasks should be selected.
If this helped, please mark it as Helpful — and if it solved your issue, I'd be grateful if you accepted it as the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you kmohammed for your answer.
If the script is executed on each task, i would have seen in the log multiple instances of my message.
But I only see one.
When I use your example, the template exit on the first record (because It doesn't match) an no other task is assigned to the template. There is no loop on the Tasks.
In addition, in the script field, the OOTB comments line says :
Have you been able to make it work like you say?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Amar,
Thank you — and you are right to correct me. I was wrong in my earlier reply.
The out-of-the-box comment is authoritative: the condition script runs once, not once per task, and it must return an array of reconcile_duplicate_task sys_ids. Your single gs.info entry confirms that — if it ran once per task, you would see one log entry per task. My earlier per-task true/false explanation, and the example returning current.short_description == ..., were therefore wrong, and I am sorry for the misleading advice. That example would indeed exit on the first non-matching record, exactly as you found, because it was never the right shape for this script.
On why all tasks are still being selected, the likely cause is the option you mentioned in your original post: "Automatically select all de-duplication tasks that match the selected class." With that checked, the template selects every task for the class, which overrides the array your script returns. Uncheck it and re-test with your original script — the one that builds tskList and returns it — and the template should then use only the sys_ids in that array.
To isolate it, try a hard-coded return first, for example returning an array containing just 1-2 known task sys_ids. If only those tasks are assigned, that proves the template honours the returned array. Then go back to building the array in one pass, as your original script already does: loop through the matching reconcile_duplicate_task records inside the single script execution, collect the matching sys_ids into the array, log it once, and return the array.
To answer your question directly: no, I have not made it work the per-task way I described, because that is not how this script works — it works the way you and the out-of-the-box comment describe, returning an array in a single execution.
If this helped, please mark it as Helpful — and if it solved your issue, I'd be grateful if you accepted it as the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I got the reason and solution;
- When the option "Automatically select all de-duplication tasks that match the selected class" is activated, all the active tasks of the class on which apply the template are associated (attribute "De-duplication Template" on the task).
- But only tasks that satisfy the condition or tasks in the array returned by the condition script are processed.
- The non-processed Tasks remains related with the template and thus unavailable to other templates.
- If later, the option "Automatically select all de-duplication tasks that match the selected class" is unchecked, the task already related to the template are not unrelated. If they are not closed, or have been reopened, they are reprocessed what ever is the condition. (this was my case)
If the option "Automatically select all de-duplication tasks that match the selected class" is not activated at the first run, only tasks that satisfy the condition are related to the template.
I've not found a way to dissociate a task from a template. I had to delete my tasks and run the CMDB Health Jobs to recreate the tasks.