flogo-lib
flogo-lib copied to clipboard
support if statement
I'm submitting a ... (check one with "x")
[] bug report => search github for a similar issue or PR before submitting
[*] enhancement request
[] feature request
[] support request
[] general question
Current behavior (how does the issue manifest):
Today we only support ternary expression for one level if else case, it has the limitation and it does not support nested ternary expression.
Expected behavior:
We should come up with an if
statement expression which supports nested if else. such as:
if true {
"yes"
}else {
"no"
}
if string.equals("FLOGO", "FLOGO") {
if string.equals("if", "if") {
"Hello FLOGO IF expression"
}
}else {
if string.equals("TIBCO", "TIBCO") {
"Hello TIBCO"
}
}
The if
statement gives the user more flexibility to achieve more complex use cases
Minimal steps to reproduce the problem (not required if feature enhancement):
What is the motivation / use case for changing the behavior?
Please tell us about your environment (Operating system, docker version, browser & verison if webui, etc):
Flogo version (CLI & contrib/lib. If unknown, leave empty or state unknown): 0.X.X
Additional information you deem important (e.g. issue happens only occasionally):
There is a use case that query salesforce approval object and return the status of the record with description. Here is the status and expect return messages:
Submitted -> Your request has been submitted.
Pending -> Your request staus still pending.
Approved -> Your request has been approved.
Rejected -> Your request has been rejected
REassgined -> Your request has been submitted for approval but assigned to a different approver.
Recalled -> You request has been recalled.
Possible solution
- User want to have only one return so branching not work.(we don't have branch merge today)
- Ternary expression, we don‘t support nested ternary expression so far. it might hard to read if we support nested. such as:
$activity[query].output.Approval == ”Submitted“ ? ”Your request has been submitted“ : ($activity[query].output.Approval == ”Pending“ ? "Your request staus still pending" : ($activity[query].output.Approval == "Approved" ? "Your request has been approved": ($activity[query].output.Approval == "Rejected" ? "Your request has been Rejected": ($activity[query].output.Approval == "Reassgined" ? "Your request has been reassigned":($activity[query].output.Approval == "Recalled" ? "Your request has been Recalled":"Unknow staus")))))
- If statment
if $activity[query].output.Approval == ”Submitted“ {
”Your request have been submitted“
}else if $activity[query].output.Approval == "Pending" {
"Your request staus still pending."
}else if $activity[query].output.Approval == "Approved" {
"Your request has been approved."
}else if $activity[query].output.Approval == "Rejected" {
"Your request has been rejected"
}else if $activity[query].output.Approval == "Reassgined" {
"Your request has been submitted for approval but assigned to a different approver"
}else if $activity[query].output.Approval == "Recalled" {
"You request has been recalled."
}else {
"Unknow staus"
}
We can see the if/else
statement much simple and clear for this kind of usecase.
@mellistibco @fm-tibco Please let me know your thougts? or possible others resolution?
@mellistibco @fm-tibco please add your comments and suggestions.
thanks @lixingwang ... I just still think I'd rather have a scripting activity that would support something like this rather than supporting it via the expression syntax. I really think expressions should be lightweight expressions and should not begin to morph into a scripting language...
Thanks, @mellistibco, it makes sense. I thinking about to add an activity to support this. BTW, I created #263 to support nested ternary expression.