Hi there AppWorks fans,
Welcome to a new installment of AppWorks tips.
This is an addition (or part 2) on this previous post. We’ll have a look (based on what we have so far) if it would be possible to claim a new case/task once the current one is “DONE”. So, we’re looking for some trigger moments:
- For a ‘Case’, the trigger moment (in our example) is the completion of the lifecycle. After this you get assigned to the next case in the
lst_all_cases
; We keep it simple, but a next step would be to only pick the next one corresponding to your skill level! - For a ‘Task’, the trigger moment (in our example) is the completion of the task itself! I assume our tasks land in different queues
New cases
,Review cases
, andFinal cases
; We keep it simple with only theNew cases
queue and grab a new task when “DONE” with the current task.
Time for some advanced business logic…
Let get right into it…
Again, two sections in this post…Let’s mumble-jumble a bit on the implementation strategy; Always a good thing to do with your colleagues!
The ‘Case’; Well, picking up a new case is not a feature out of the box from the platform. The trigger however is! This will just be an ordinary ‘Rule’ BB checking the ‘Completion’ state of the lifecycle. The action falls under the ‘Advanced action’ feature for a rule where we call the appropriate actions via a BPM. So, my next step would be the implementation of such a BPM with specific logic to manage the next assignee. This means webservices to “find” all cases ordered by creation date (I guess), get the first one and make use of a secret assignee webservice to make it happen…AND don’t forget to read the flag if auto-assignment is enabled! Interesting enough? I just pop it out of my sleeve as I’m writing! 🤣
The ‘Task’; Also, picking up a new task isn’t a feature OOTB from the platform. So, the same principle here. When the task is completed, we trigger a BPM managing the rest of the business logic…
Case implementation
Let’s first plot our action plan into something touchable. So, our case will get a ‘Rule’ BB with name e_lc_complete_start_bpm_next_case
. The condition will be Lifecycle.InstanceStatus == 'Complete'
, and the action will trigger BPM bpm_next_case
with this pseudocode:
1 | var config = readConfig(); |
Time for BPM craftsmanship…I first plot out the flow with empty activities:
Next, we apply all the webservices (from the right-click menu of an activity):
The
findUnassignedCasesOrderedByCreationDateDesc
operation is enabled on the case ‘Web Service’ BB. Just like this:The second filter (in the screenshot above) is for our implementation choice; The descending ordering on ‘Tracking.CreateDate’ is done in the last tab…An extra task for you to explore!
Before you can publish, make sure the decision is configured properly; Make it an exclusive check (only one output and not parallel) and read the config setting:
Publication should be possible, but you can’t run it properly yet! Why? Because we miss the message mapping parts! This is the consolidated view of my mappings on the activities. Comment me if you don’t have a clue, but I guess by now you’ll understand the principles of BPM message mapping.
Extra notes on those mappings:
- To empty a field with a service call, you can make use of the “nil” attribute:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"
. In the messagemap assignments you have an extra option to set it (see screenshot). - You don’t need to map the Id’s itself; The ItemId’s are enough…At least, that’s my experience!
- Always change “Replace with select” to “Replace with expression” if the default mapping is changed (after a
<Ctrl>
click from source to target!); So, when you use a real expression…This is not always needed, but just a best practice! I updated my expression (see the[1]
) to get the first element from the “Find” result. - Be cautious when adding 2 of the same webservice calls (‘updateCase’) in one BPM! For some reason (?) the activities pick up mappings from each other! A common BPM feature/bug(?) you should be familiar with. Just swallow it and go with the flow! 😎
When ready, publish it, but don’t do anything yet as we first need that event type of ‘Rule’ BB to trigger the BPM. This is a real simple implementation like this:
Well, where are we waiting for…Publish again, move to runtime. Create a new case-related case instance, move it through the lifecycle and see if the next case is assigned to you (and the old case gets unassigned)! How easy…Did it work the first time? Hell no!…What is the PIM artifact telling me?
As expected…First test is OK! 😂 Let’s enable our feature flag in ‘app/admin’ and give it a second try…This time it’s working fine!
The final version checks also if the queue is empty; Otherwise, the update (to assign) on the new case fails! You see that pseudocode is one thing, but in realtime you’ll always face those bumps in the road!
This is my final BPM with proper naming:
Let’s jump to the next one…
Ohw…before I forget; Make the BPM short-lived to get direct feedback/updates in the UI! #KeepYourEndUsersHappy! 😜
Task implementation
Here also, first something touchable…So, our LifecycleTask entity will get a ‘Rule’ BB with name e_tsk_complete_start_bpm_next_task
. The condition will be Task.State == 'Completed'
; The action will trigger BPM bpm_next_task
with this pseudocode:
1 | var config = readConfig(); |
Did you find the difference in the ‘ItemId’ of a lifecycleTask entity instance and the ‘Id’ of a real inbox task instance? If so, you see a direct difference between the “old” part of the platform Id’s compared with the “new” entity modelling ItemId’s! Where did we see this before? Well, at user level! Do a SOAP request on operation ‘FindUserByName’ and after that a ‘ReadUser’ with the ‘ItemId’. Compare that with the ‘GetUserDetails’ operation where you receive a ‘UserId’ (not an ‘ItemId’). Now you see the platform has a long history…Interesting stuff!
Time for BPM craftsmanship…This time I do a simple ‘Save as’ action on the previous BPM as “The Skeleton” is the same. This is the screenshot after cleaning and updating it to continue our journey:
You see I do a sub-process grouping trick to have the option available to add a condition true()
on multiple activities; See it as the static block in the pseudocode to play with. This true() | false()
condition trick is always useful to temporary skip things in development instead of removing activities…Just a trick from the godfather of BPMs! You know who you are…😜
Now what? Well, attach services again…
Extra notes to help you (comment me if you don’t follow here):
- The
GetTask
service isn’t available directly in your BPM. For this you need to add a new runtime reference (of type ‘webservice’) into your project. See the same context menu as when you create a new entity. - This reference also contains the
GetHumanTasks
andClaimTask
service operations
In the image of the first note, I just discovered a typo in my BPM name! I’m human too…In the final solution it’s renamed to
bpm_next_task
. 😁
Next step is adding the correct message mapping for the activities where GetHumanTasks
is the most interesting call to make…Have a look first in the ‘Web Service Interface Explorer’ artifact for a test request like this:
1 | <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> |
ReThink and conclude this is just an ordinary SQL query in CQL-format for XML compatibility! Specially for you, I enabled my Postgres DB with extra logging…This is the outcome behind it (for what it’s worth!):
1 | SELECT NOTF_TASK_INSTANCE.TASK_INSTANCE_ID AS "TaskId", |
Fascinating! 🤓 But we’re getting off track here…The message mapping…This in the consolidated view from my side:
Extra notes on those mappings:
- The ‘LifecycleTask’ has ‘ItemId’ and ‘ItemId1’ as input; Use the second one (‘ItemId1’) as the other one is the ‘Id’ of the parent entity (our case!)
- XML data is key for the ‘GetHumanTasks’ activity; Watch the use ‘Add XML structure’ in the assignments
Finally, we need a ‘Rule’ BB (e_tsk_complete_start_bpm_next_task
) to trigger the BPM…
With this in place, it’s time to publish it all again and have a try in runtime…So, make a task-related case, complete the task and see if the BPM does its tricks well. The greatest question of all questions: Did it do the tricks well the first time? Well, it works; It even works so well that it directly picks the next task in the lifecycle state and isn’t picking up the old one…So, we need to order ASC to get the oldest first; You already saw this coming…right? 😅
This is my final BPM with proper naming and error-catch when the claiming fails (because it’s the last one?):
During all my testing I found another interesting thing…When you complete the ‘Finalize’ task, you’ll reach the end of the case lifecycle…Guess what triggers then! 🤐 I leave that one for you the figure out! It’s time for weekend…
Nicely “DONE”…Before starting this post I didn’t have a clue where to start, but you see I’m also figuring out features as we go. Have your learnings out of it and spread the word! I’m also open on any feedback on the things I’m doing and presenting…Just to make sure I’m improving myself as well; Which will benefit you too for a next new post on AppWorks Tips; Have a great weekend…Cheers.
Owh…And is the downloadable solution; “Monkey-proof” so far!? Probably not, but it triggers creativity and exposes ways of doing things! 😁
Don’t forget to subscribe to get updates on the activities happening on this site. Have you noticed the quiz where you find out if you are also “The AppWorks guy”?