Showing posts with label SOA. Show all posts
Showing posts with label SOA. Show all posts

Wednesday, June 18, 2014

IF Else in Assign/Script Activity in SOA/BPM

If else conditional assign in Assign or Script Activity of SOA or BPM

Note: It's not a complete solution. however, you can use this method in most of the cases.


Use Case:

Assume an input string which can have value "Submit" or "Cancel" and based on this you want to output string to be either "APP" or "REJ"

if  input_arg = "Submit"
Then
output_arg = "APP"
Else
output_arg = "REJ"


General way of giving a solution for this to write an XSLT or use switch/exclusive gateway and have 2 Assign/Script tasks to assign the appropriate value to the output element.

Here in this example, I will use "translate" function to achieve the same without gateways and in a single Assign/Script Task.



The xpath expression used here is:

translate(string(contains(bpmn:getDataObject('projectDataObject1'),"Submit")),"trufalse","APPREJ")

Lemme split the function and explain it in detail.

1. contains(bpmn:getDataObject('projectDataObject1'),"Submit")  :  This is obvious, checking whether the input argument has the string "Submit". If yes, the function returns "true" else it returns "false"

2. string(contains(bpmn:getDataObject('projectDataObject1'),"Submit")) : Converting the above returned Boolean "true or false" into a string.

3. translate(string(contains(bpmn:getDataObject('projectDataObject1'),"Submit")),"trufalse","APPREJ") : This is the important part, translate function does replacement each character by character.
So, in this above statement  
string(contains(bpmn:getDataObject('projectDataObject1'),"Submit"))  is the input argument to "translate" function

"trufalse"  Indicates what characters to be replaced. This is the 2nd argument.
 "APPREJ"  Indicates with which characters they need to be replaced. This is the 3rd argument to the function.
 "t" would be replaced with "A"
 "r" would be replaced with "P"
"u" would be replaced with "P"
 "f" would be replaced with "R"
so... on

The last letter "e" doesn't have the corresponding replacement element. So, that will be ignored. 
Even "true" has "e" in it, but I didn't mention it explicitly, since we need to mention each character only once. 


So, finally summing up, based on the input argument containing "Submit" or not, the output argument will be updated to "APP" or "REJ".


This might be little confusing :-)

To help you understand more, here are few examples on how the translate function works:

translate("AABBCDBA","ABCD","XYZW") AABBCD is the input and output would be XXYYZWYX
Each character is replaced appropriately.

translate("ABC123DDC","ABCD32154","abcd00000") :   ABC123DDC is the input here and output would be abc000ddc


You can have pretty complicated xpath's to achieve nested if's too. Example here:

translate(string(not(
contains(bpmn:getDataObject('applicationDataDO')/ns:ApplicationStatus,'REJ'))),
 'trufalse',
concat(translate(string(
contains(bpmn:getDataOutput('outcome'),'REJECT')),'trufalse','REJSUB'),'REJ'))
  

You can literally replace any character with any character. Just make sure what you are doing. :-)


Oracle BPM 12c supported much easier way of nested if's in Script tasks, I will post on a blog in it soon. Keep watching !


Shoot me in the comments, if you need any further help.

Monday, April 28, 2014

Get List of Users in Application Role of BPM.


Get list of users assigned to a Application Role in BPM.

How to get list of users assigned to a Application Role?

you can use function  ids:getUsersInAppRole() to get the list of users for an application Role.
Check my previous post on how to use Identity functions.
Here is the link.

http://kvkvinod.blogspot.in/2014/04/bpmsoa-identity-functions-ex.html

 

There are different options for this function. You can get list of users for a BPMProcess role or BPMComposer role or even for soa-infra. You can see the same in the description.

Similar to my earlier post, you need to create a variable based on "Users" element from the schema and use "Copy List" to assign the output of the function to the  variable as shown in the below picture.

 

Leave a comment if you need any help with this.