Skip to main content
scottf0004
June 12, 2024
Solved

Logic - do not display if value is empty

  • June 12, 2024
  • 12 replies
  • 0 views

In my gridColum, I am displaying an email link, with an envelope-o icon. 

However, if the value of the field is empty or null, it's still displaying the icon.

How do I add the if logic to this code to not display the icon if the value of the field is empty or null? I've edited the code below to shorten the field recordtype! info.

a!richTextDisplayField(
  value: {
    a!richTextItem(
      text: {
        a!richTextIcon(
          icon: "envelope-o"
        ),
        a!localVariables(
          local!fullString: fv!row['recordType!technicalPointOfContact'],
          extract(
            "--beginning--" & " " & local!fullString,
            "g--",
            " <"
          )
        )
      },
      link: a!safeLink(
        uri: "mailto://" & extract(fv!row['recordType!technicalPointOfContact'], "<",">")
      )
    )
  }
)

In addition the following code is throwing "Invalid Syntax errors" 

  link: a!safeLink(
        uri: "mailto://" & extract(fv!row['recordType!technicalPointOfContact'], "<",">")
      ),
   linkStyle: "STANDALONE" <--- invalid syntax???
   )

Best answer by mikes0011

Here's an expression rule I just whipped up that will extract the name and email, presuming the formatting is exactly on-spec and no funny business has happened with special characters.  Note that extract() returns an array, so we have to take care to cast that as a singular result (my favorite way is just to take the first index() of the result).

a!localVariables(
  local!name: index(extract(
    "--beginning--" & ri!emailString,
    "ng--",
    " <"
  ), 1, null()),
  
  local!email: index(extract(
    ri!emailString,
    "<",
    ">"
  ), 1, null()),
  
  
  a!map(
    name: local!name,
    email: local!email
  )
)

12 replies

davidj137213
Brainy
June 12, 2024

From "extract" the rule is wrong...and that makes the compiler throws the Syntax error

 

What do you want to do with that instruction?

June 12, 2024

Add showhen condition in a!richTextDisplayField. 

a!richTextDisplayField(
  value: {
    a!richTextItem(
    )
  },
  showWhen: a!isNotNullOrEmpty(fv!row['recordType!technicalPointOfContact'])
)

mikes0011
Brainy
June 12, 2024

I would suggest putting the showWhen condition in the RichTextItem object actually - the richTextDisplayField still needs to show up (afaik) so the column has some content, even if it's blank.  additionally my normal trick here would be to add one extra RichTextItem to the displayField's array, set to show ONLY when the email is blank, in which case i show like "(none)" using nice richText formatting also.

June 12, 2024

OK. Thanks for the suggestion.[emoticon:bdff6301f6b94530b1aa5f5df5413e7b]

stefanhelzle0001
Brainy
June 12, 2024

No answer to your question, but instead of constantly parsing this weird email address format when using it, I suggest to do that once when storing it to the database.

mikes0011
Brainy
June 12, 2024

You really, really, really ought to consider moving this parser to its own expression rule.  Trying to have this code hard-coded into a grid like this just makes stuff un-readable, and then of course when you get little errors like this it's also very hard to test.

mikes0011
mikes0011Answer
Brainy
June 12, 2024

Here's an expression rule I just whipped up that will extract the name and email, presuming the formatting is exactly on-spec and no funny business has happened with special characters.  Note that extract() returns an array, so we have to take care to cast that as a singular result (my favorite way is just to take the first index() of the result).

a!localVariables(
  local!name: index(extract(
    "--beginning--" & ri!emailString,
    "ng--",
    " <"
  ), 1, null()),
  
  local!email: index(extract(
    ri!emailString,
    "<",
    ">"
  ), 1, null()),
  
  
  a!map(
    name: local!name,
    email: local!email
  )
)

mikes0011
Brainy
June 12, 2024

Given that, you would re-write your original column value to something more like this, assuming we call the above expression rule "rule!GLBL_parseEmail()" for example:

a!richTextDisplayField(
  value: a!localVariables(
    local!emailMap: rule!GLBL_parseEmail(emailString: fv!row['recordType!POC etc']),
    {
      a!richTextItem(
        showWhen: a!isNotNullOrEmpty(local!emailMap.email),
        text: {
          a!richTextIcon(
            icon: "envelope-o"
          ),
          local!emailMap.name
        },
        link: a!safeLink(
          uri: "mailto://" & local!emailMap.email
        ),
        linkStyle: "STANDALONE"
      ),
      
      a!richTextItem(
        showWhen: a!isNullOrEmpty(local!emailMap.email),
        text: "(none)",
        size: "SMALL",
        style: "EMPHASIS",
        color: "SECONDARY"
      )
    }
  )
)