Rule to calculate length of String

rule to calculate length of a string. if the length of string exceeds 50, then show the access text with (...more.) else returns the sring.

  Discussion posts and replies are publicly visible

  • https://docs.appian.com/suite/help/24.1/Appian_Functions.html  -> "text"

    The standard primitive function for text length is simply "len()".

    For read-only text displays with such a length cut-off, you can simply use the Rich Text Display Field and in cases where the length is greater than 50, show the left("my text", 50) characters of it, then "(more)" - what's better, with the Rich Text Display Field you can then make just the "(more)" tag clickable and expand the displayed text to show the entire thing.  I've used this trick in grids where a column has text that sometimes gets too long for comfortable display by-defult.

  • Use this code....

    a!localVariables(
      
      local!text: " The local variable to use when evaluating the given expression. Use the 'local!' domain to define and reference individual variables. By default, a local variable will automatically update when any variables it references are changed. To change the way variables are updated, use the a!refreshVariable() function. Variables can be refreshed under the following conditions: after each reevaluation, periodically on an interval, or when other variables change.",
      
      local!result:if(
        condition: len(local!text)>50,
        valueIfTrue: concat({left(local!text, 50),  " (more...)"}),
        valueIfFalse: local!text
      ),
      
      local!result
      
    )

  • 0
    Certified Senior Developer

    A sample code to acheive that. Just replace the data  and limit with rule inputs and you can re-use.

    a!localVariables(
      local!data: "A good example of a paragraph contains a topic sentence, details and a conclusion. 'There are many different kinds of animals that live in China. Tigers and leopards are animals that live in China's forests in the north. In the jungles, monkeys swing in the trees and elephants walk through the brush. There are camels in the deserts in China that people use for transportation. Lots of different kinds of animals make their home in China",
      a!richTextDisplayField(
        value: {
          a!localVariables(
            local!showMore: false,
            {
              a!richTextItem(
                text: if(
                  local!showMore,
                  local!data,
                  left(local!data, 50)
                )
              ),
              char(32),
              a!richTextItem(
                link: a!dynamicLink(
                  value: if(local!showMore, false, true),
                  saveInto: local!showMore
                ),
                text: if(local!showMore, "..less", "..more"),
                showWhen: len(local!data) > 50
              )
            }
          )
        }
      )
    )

  • 0
    Certified Senior Developer

    Hi   you find the logic directly in the patterns tab in interface design tab, you can change the logic as per your requirement