Addi different tag background on condition

Certified Associate Developer

Hello, 

I have questions regarding tags background, 

Let's assume I have different statuses written with text in the DB

backgroundColor:
if (rule!BBO_CaseStatusToText(rf!status) = "Open Status","SECONDARY","POSITIVE")
)

Let's assume that I have more than 2 statues

Open Status

Pending Status

Closed Status

How I can create multiple if conditions or case switch where I can made the evaluation depending on the status provides show me different background.

Any help will be appreciated.

Thank you. 

  Discussion posts and replies are publicly visible

  • There are few ways. Check out the choose function or the displayvalue function for a couple of ideas.

  • 0
    Certified Lead Developer

    I'd suggest creating an Expression Rule where you feed in a status ID / status text, and the expected output is a single color value.  Inside that expression rule you could have a big ugly nested IF statement or CHOOSE statement or whatever works best for you (and experiment with different options), but where you need that logic you'll have the freedom to just call a single, clean rule and be relatively assured that it'll work.

  • My recommendation is to use a decision table to map status to color or an expression using displayvalue which would look like displayvalue(ri!status, {"status1", "status2", ...}, {"color1", "color2", ...}, "defaultcolor")

  • 0
    Certified Senior Developer

    if(
                    fv!row['recordType!{0f38087c-3fac-4414-a181-694ccda3115e}Sales Order.fields.{status}status']=cons!ECOC_STATUSES[1],
                    a!tagField(
                      tags: a!tagItem(
                        text: "Active",
                        backgroundColor: "POSITIVE"
                      ),
                      size:"SMALL",
                      align: "CENTER"
                    ),
                    if(
                      fv!row['recordType!{0f38087c-3fac-4414-a181-694ccda3115e}Sales Order.fields.{status}status']=cons!ECOC_STATUSES[2],
                      a!tagField(
                        tags: a!tagItem(
                          text:"Closed",
                          backgroundColor: "NEGATIVE"
                        ),
                        size:"SMALL",
                        align: "CENTER"
                      ),
                      a!tagField(
                        tags: a!tagItem(
                          text: "Cancelled",
                          backgroundColor: "SECONDARY"
                        ),
                        size:"SMALL",
                        align: "CENTER"
                      )
                    )
                  )

    I think this code is helpful if we want to display more than 2 Tags.

  • You have a choice:

    • nested if() statements 
      • these get progressively harder to read and maintain the more you nest them but if you only have 2 or 3 nestings then it's the quickest way to implement 
    • displayvalue() function
      • you create and manage two arrays - one for the value you want to interrogate against and one for a "decode" of that value, and use this function to pick the required decoded value based upon the relative position of the value you're interrogating against
    • choose() function
      • this is like displayvalue except you have to map the value you're using as the "lookup" to an explicit position in the list of choices in the function
    • decision rule
      • this encapsulates your lookup into a separate object and can be really useful for large lists/complex combinations of data but is "heavyweight" compared to any of the above