I saw such a example code in APPIAN DEVELOPER course practice document. (Expressions: Transform Your Data, Build an Application: Step 4)
I couldn't understand why if() coukd take arguments more than 3. The usage of if() should be "if(condition, valueIfTrue, valueIfFalse)" according to official doc.
proper( if( isnull(ri!user), "", isusernametaken(ri!user), user(ri!user, "firstName") & " " & user(ri!user, "lastName"), joinarray(split(ri!user, "."), " ") ) )
Discussion posts and replies are publicly visible
Hi don't have the answer to "Why" but I do have one for "How" The total number of arguments should be odd, more than 3. Every even argument acts as a statement and every odd arguments act as a condition. The last statement will act as a false statement for the third last argument.
Thank for your immidiate reply, Harshit!
You mean if() which has 5 arguments in Appian can be equal to such statements in Ruby.
if expression1 then value1 elsif expression2 then value2 else value3 end
Maybe I understand that, but it is strange that this basic information is not mentioned at all in the official document.
docs.appian.com/.../fnc_logical_if.html
While this technically works, I consider this to not be a best practice. I am going to contact Appian to only use officially supported functionality in the courses.
This has long been a trick we can sometimes use to avoid messy if() nesting - with the caveat that the functionality is semi-unsupported, and completely unsupported in the GUI interface editor (i found at one point that if you enter it into the code, it'll refuse to switch back to the GUI editor, for anyone who cares about using that at all).
Fortunately now there's no longer any need to do this, since Appian introduced a!match() in 22.1, which handles a list of conditions in a way that recreates an "if, elseif, elseif, (...), else" statement with any number of parameters with no nesting needed. In that case I think we can pretty much consider the multi-condition if() functionality deprecated (other than the fact that it isn't officially documented anyway), though I don't expect its back-end functionality will change anytime soon since that could break exisitng code.
I agree though, I'm not sure why they included that undocumented functionality in any training documentation (but also I'm not super surprised).