Click Here

Saturday, 10 March 2018

Alternate way(1 div, 1 div not) of using If Else statement in SOA/BPM

Scenerio:-

Most of the time, we have a requirement of the use of IF-ELSE kind of code inside our Script-task/assign activity in SOA/BPM.

Existing way to handle:-

To handle this requirement, for almost all the time we think of using of XSL transformation and inside that we either go for "IF-ELSE" or "Choose-when-otherwise" option and there we will do the implementation.

Issue with Existing way solution:-

The problem with this is, we will land into the long process where we need to write an XSL Transformation or by using a switch/exclusive gateway and have to use two Assign/Script tasks to map the appropriate value to the output element.

Alter/Easy way of implementation:-

In this blog, I will explain you the "Alter/Easy way of implementation of if-else".

Let me explain you the scenario in more layman language:-

If(if_condition_logic)
return ifAssignedValue;
else return elseAssignedValue;

Here, I will make use of "1 div" , "1 div not".

Syntax:-

concat(substring("ifAssignedValue",1 div (if_condition_logic)),substring("elseAssignedValue",1 div not (if_condition_logic)))

Explanation:-
If the condition(inside 1 div{if_condition_logic}) is evaluated to be true then "ifAssignedValue" value will be assign to the variable. If the condition{if_condition_logic} is not true, then "elseAssignedValue" value will be assign to the variable.

NOTE:- The same condition will be use in 1 div and 1 div not.

Example:-

Lets consider you have a requirement, where we need to check for the output of $city , if its value is coming to "Bangalore", then return that value; If the value is not "Bangalore" or the value is other then "Bangalore", then return "NotBangalore" or the value which is coming from the request.

If(country/state/city='Bangalore')
then return Bangalore;
else return city_value;

Here, we can use this logic by 2 ways:-
1) By hard coding the result of both IF and ELSE. i.e If($country/state/city="Bangalore") got success then "Bangalore", else "NotBangalore"

concat(substring("Bangalore",1 div ($country/state/city="Bangalore")),substring("NotBangalore",1 div not ($country/state/city="Bangalore")))


2) By hard coding the IF part and getting the runtime value to the ELSE part. i.e if($country/state/city="Bangalore") got success then "Bangalore", else value of whatever the value of $country/state/city.

concat(substring("Bangalore",1 div $country/state/city="Bangalore")),substring('$country/state/city',1 div not ($country/state/city="Bangalore")))


Hope, this might help you.
please let me know in case you need further details.