I have a CDT which can contain an array of product information and a Constant wh

I have a CDT which can contain an array of product information and a Constant which contains specific product codes. In my user interface, I can display a specific piece of text where the value of CDT.fieldname = cons!value, however it only works if the Constant contains a single value. How can I perform a match where there are multiple values in the constant. In my form, I have the following:

if(
index(
ri!ItemList,
"productCode",
""
) = cons!MY_SOFTWARECODE,
a!paragraphField(
value: "This product licence is perpetual.",
readOnly: true
),
a!paragraphField(
value: "No match.",
readOnly: true
)
)

The CDT ItemList contains the fields productCode, productName, price.

The constant contains the values Word123,Excel123

As the user is filling the form and picks a product that mat...

OriginalPostID-203840

OriginalPostID-203840

  Discussion posts and replies are publicly visible

  • ...ches a value in the Constant, the paragraph field should be populated with the text "This product licence is perpetual". If the product code is not listed in the Constant, then the paragraphfield should remain hidden. for debugging purposes, I currently have it displaying "No match".
  • Hi Andy,
    Try the modified code below :
    if(
    contains(
    cons!MY_SOFTWARECODE,
    index(
    ri!ItemList,
    "productCode",
    ""
    )
    ),
    a!paragraphField(
    value: "This product licence is perpetual.",
    readOnly: true
    ),
    a!paragraphField(
    value: "No match.",
    readOnly: true
    )
    )
    Also please make sure that the constant is multiple type constant.
    Hope it helps.
  • If I understand your use case correctly, you want to perform the above same operation when you have "multiple" values in your constant unlike single value which you said is working for you.
    If yes, then just simply refer to the index of your constant array against which you want to match your search results for.
    For instance, from your above stated example, if you want to show the paragraph for "This product licence is perpetual." to match it against a value (product code) sitting in the constant at lets say index '2' then your code would be..

    if(
    index(
    ri!ItemList,
    "productCode",
    ""
    ) = cons!MY_SOFTWARECODE[2],
    a!paragraphField(
    value: "This product licence is perpetual.",
    readOnly: true
    ),
    a!paragraphField(
    value: "No match.",
    readOnly: true
    )
    )
                        
                        
    >> Other approach, if you think that the ordering of the values in the constant array should not matter, then you code should look something like:
    if(
    index(
    ri!ItemList,
    "productCode",
    ""
    ) =
                         /*Updated block code BEGIN*/
                         index(cons!MY_SOFTWARECODE,wherecontains(<value to search for>,cons!MY_SOFTWARECODE),{}),
                         /*Updated block code END*/

                         a!paragraphField(
    value: "This product licence is perpetual.",
    readOnly: true
    ),
    a!paragraphField(
    value: "No match.",
    readOnly: true
    )
    )
                        
    Hope it helps or let me know if I misunderstood your problem.
                        
  • Hi Andy,

    Usually we use wherecontains() or filter() to accomplish text filtering. Wherecontains() is slightly more out of the box but more restrictive in terms of what you can do.

    Hope that helps.
  • @andyb Hi, there could be various ways to do as specified above by other practitioners. But it would be worth knowing about the behavior of the if() in case of your example.

    So let's take the 'condition' argument of the if() in your example which is as follows:
    index(ri!ItemList, "productCode","") = cons!MY_SOFTWARECODE

    Here, index(ri!ItemList, "productCode","") returns results in a list format. And cons!MY_SOFTWARECODE also returns results in list format. Thereby ultimately you end up in returning a list of boolean values after comparing both the lists and these list of boolean values will be passed to 'condition' argument of if(). Execute the following examples in the expression editor and see the results, and they are the results that will be used as condition in if().

    Example 1: index({{productCode:"SWCODE1"},{productCode:"SWCODE2"},{productCode:"SWCODE3"}},"productCode",{}) = {"SWCODE2","SWCODE3","SWCODE1"}
    Example 2: index({{productCode:"SWCODE2"},{productCode:"SWCODE2"},{productCode:"SWCODE3"}},"productCode",{}) = {"SWCODE2","SWCODE3","SWCODE1"}


    if() function returns 'valueIfTrue' or 'valueIfFalse' as long as the 'condition' argument isn't in a list format. But if the 'condition' argument is in List format, then if() function behaves differently and it has been mentioned in the 'Notes' section at https://forum.appian.com/suite/help/16.1/Logical_Functions.html#if.28.29.

    Also I believe that a decent discussion has took place at /search?q=OriginalPostID-146293 re the behavior of if() when list is used as condition.
  • Hi siddharthg837,

    I don't think I explained my example clearly enough. My Constant contains a series of product codes which in this case all relate to versions of the same product. In my application, the software code could match any one of the codes in the Constant, so I have to check each member of the array and can't reference a specific member e.g. [2]. I'm probably over-engineering this in my mind, but I was thinking something along the lines of finding the length of the Constant array and then looping through each value to see if there is a match.