
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 11:30 AM
Hi Team,
A weird one today that I ca't figure out, hoping someone can help me with this. My requirements is to copy the attachments from the originating HR Case to the Approval record - this works fine with the below and all attachments are copied to each approval task created as part of the workflow attached when creating the HR Case via the portal (using a record producer).
BR on sysapproval_approver table, no Condition, Async Rule, on insert, advanced script is:
(function executeRule(current, previous /*null when async*/) {
GlideSysAttachment.copy('sn_hr_core_case_workforce_admin', current.sysapproval.sys_id, 'sysapproval_approver', current.sys_id);
})(current, previous);
So the above works perfectly - for all cases. However now I want to limit this to only a particular HR Service.
However - if I add a condition in the 'when to run' tab this code it stops working. I have tested a simple message using my condition and this works, so I know the condition is correct. However when using them both together this doesn't work.
The condition is dot walked approval for->HR Case->HR Service. If I use a simpler condition - like status='Not Yet Requested' this works.
Anyone have ideas why this might be the case?
Thanks
Carl.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2018 12:53 PM
Hi All,
I found a few solutions to this so am documenting these for anyone else in the future. The best solution will depend on your requirements.
After investigating this further it seems the 'approval for' (syspaproval) field wansn't blank, but seemed to have an invalid link (or incomplete HR Case as it couldn't find the HR Service) when the Approval Task was created.
Solution1
-Add a 'timer' into the workflow BEFORE the 'Generate Approvals' action (2 minutes worked for me).
-Write the BR: Table='Approval', Async, on Insert, condition 'Approval for.HR Case. HR Service=<required service>'
Script is:
(function executeRule(current, previous /*null when async*/) {
GlideSysAttachment.copy('sn_hr_core_case_workforce_admin', current.sysapproval.sys_id, 'sysapproval_approver', current.sys_id);
})(current, previous);
This will wait before creating the approval records and this seems to ensure the link to the HR Case is complete, with all the HR Case details, so the condition to the HR Service works great.
Note: This means the user won't see the approval tasks being generated at the time of logging, so this might lose some visibility for them.
Solution2
-Add a 'timer' into the workflow AFTER the 'Generate Approvals' action (2 minutes worked for me) and ensure it's BEFORE the first approval.
-Write the BR: Table='Approval', Async, on Update, condition: 'Approval for.HR Case. HR Service=<required service>' AND 'updates is 1''
Script is the same as above.
This solution will create the approval records as soon as the HR Case is logged and the workflow is run. It then WAITS 2 minutes and then moves to the approval task which updates the status from 'not yet requested' to 'requested' - at this time the 'updates' field changed from 0 to 1 and therefore the condition is valid, the attachments are copied correctly (ONLY ONCE).
The additional benefit of this solution is that the attachments are't copied until the approval task is activated (set to 'requested') so if any attachments are added, removed, updated etc.. these will show correctly in the later approval tasks.
It allows the customer to see the approvals tasks being created right at the front, which provides them the view of these when they first log their HR Case.
Hope this helps someone else out - thanks everyone for your help with this.
Cheers
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 11:38 AM
I think when you are dot walking and if the field is another reference field so you ghave use sys_id.
if you can share condition it will help debuging.
Pranav
Mark my Responses as Correct and Helpful if you find it relevant.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 11:55 AM
Hi Pranav,
I'm using the standard conditions, not the script conditions. See below:
So I don't have to select a 'sys_id' as I'm using the 'show related fields' and then I am shown a lookup field.
I could use the condition of the script - but I don't know the format of the dot walking to get to the field I need to from here -if you could let me know what it is I could try this?
Cheers
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 12:00 PM
hr service is a reference field
can you use the sysid of study reward application instead of name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2018 12:03 PM
not using the condition builder as this requires a valid selection.