is there any way of updating a variable just if a reference varible change and is not null ?

Certified Associate Developer

foreach(items:local:lines,expresion:
local!searchsection:
      if(
        or(lower(left(trim(fv!item),7 ) ) = "section",
        regexmatch("\d{1,2}[.]\d{1,2}",
        left(trim(fv!item),5 )

        ))


      ,

        "Section: "& cleanwith(left(trim(fv!item),12 ), "1234567890.")
      
      ,{})

      ,
      local!section:a!refreshVariable(


        value:  local!searchsection

        ,refreshOnReferencedVarChange:
        if(
          rule!NPA_isEmpty(local!searchsection),
          false(),
          true()
        )
      ),
       local!section
      )

I'm trying to modify  the second variable just if the first variable that i  have is not null but  if it is  null i need to  keep the last value the variable had

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    let me explain a little bit better i'm looping into some  lines   each of those  lines are inside a section but a section   could start in any line  and i want  to know  which line is part of which   section  when i find a section number i want  to be able to keep it  until we get to capture the next section number.

  • 0
    Certified Lead Developer
    in reply to felixr

    In Appian Expressions, variable values cannot be changed once assigned. In interfaces, this is possible only on user interaction.

    Is this only about displaying these sections dynamically? Then, you could show the section header only if you found a section in that line.

  • +1
    Certified Associate Developer
    in reply to Stefan Helzle

    Hi  thanks for helping me today i found a work around    to do this   with   a process model

    just making another list    and looping  this way cause if i try to loop  by the  config in multiple instances  of this node the variable don't update   correctly.  but  looping with a xor   till we get to the limit  we can update the  variable each time with no problem.

    it  was about  generating a file searching for some  key phrases and  displaying  in which section it was found.

  • +1
    Certified Lead Developer
    in reply to felixr

    Hi

    If you are trying to get the Section numbers per line, this is something you can try.

    I assumed how your data would look like. 

    Let me know if the data looks different and we could come up with something to help you. Thanks

    a!localVariables(
      /*My assumption of your data*/
      local!data: " 
    Hello
    Section: 1.2
    Welcome to Appian
    Lets start
    Section: 2.3
    Contents
    Expression Rules
    
    Section: 2.8
    Process Models",
      /*Split data by new line character to get line*/
      local!lines: split(a!defaultValue(local!data, {}), char(10)),
      /*Get the line numbers which has the word Section in it*/
      local!sectionLineIndexes: where(find("Section:", local!lines)),
      /*Retrieve section names*/
      local!sectionNames: a!forEach(
        items: local!sectionLineIndexes,
        expression: cleanwith(
          left(trim(index(local!lines, fv!item)), 12),
          "1234567890."
        )
      ),
      /*Transform sectionLineIndexes array to return an array of number 
      of lines which points to index of its section's name */
      local!index: a!flatten(
        a!forEach(
          items: local!sectionLineIndexes,
          expression: {
            if(
              fv!isFirst,
              repeat(fv!item - 1, 0),
              repeat(
                fv!item - index(local!sectionLineIndexes, fv!index - 1, 0),
                fv!index - 1
              )
            ),
            if(
              fv!isLast,
              repeat(
                count(local!lines) - fv!item + 1,
                fv!itemCount
              ),
              {}
            )
          }
        )
      ),
      /*Section Names per line - defaults NA, until Section word is found*/
      local!sectionPerLine: a!forEach(
        items: local!index,
        expression: if(
          fv!item = 0,
          "NA",
          index(local!sectionNames, fv!item, "")
        )
      ),
      /*Output - for display purposes*/
      a!forEach(
        items: local!lines,
        expression: concat(
          "Line ",
          text(fv!index, "00"),
          " | Section ",
          a!defaultValue(
            index(local!sectionPerLine, fv!index, ""),
            "NA"
          ),
          ": ",
          fv!item
        )
      )
    )

    Hope it helps ! 

  • 0
    Certified Associate Developer
    in reply to agam

    Thanks this worked perfectly   thanks a lot.