Skip to main content
khabranp0001
October 6, 2021
Solved

Variable is not refreshing

  • October 6, 2021
  • 8 replies
  • 1 view

Good afternoon all.

Here is what's going on.

I am given a string, or Text variable. This variable is used to store employee IDs. Although it is one variable, it can contain several IDs (or contain none). There is nothing I can do about this and I cannot change this. Now, I need to check if this value has any of the following: no values, one value, or many values. This Text can dynamically change when a user selects IDs, or removes them, from a custom picker. If the Text has several values, I am currently using split() to separate the IDs into an array, which is working fine. Then, I have a local variable that uses the array to get the names for each of those IDs. Unfortunately, the last ID is contained in the new array, but fails to update to the name. For example, if the following IDs exist: 1, 2, and 3, It will show: Peter, Paul, and 3. I'm currently using Appian 21.3.

local!employeeIDs: if(
    isnull(ri!record.employeeIDs),
    null,
    split(ri!record.employeeIDs, ";")
  ),	
local!employeeNames: a!refreshVariable(
    value: if(
      or(
        rule!isEmpty(local!employeeIDs),
        length(local!employeeIDs) = 0
      ),
      null,
      a!forEach(
        items: local!employeeIDs,
        expression: rule!GetNameByID(fv!item)
      )
    ),
    refreshOnVarChange: local!employeeIDs
  )

If I did a terrible job explaining my issue, please let me know. I will gladly elaborate on the issue. Any and all advice will be greatly, greatly appreciated. Thanks.

Best answer by mikes0011

A secondary suggestion would be, if you're forced to stick with a Text-As-Array setup (under the assumption that the implementation of the array is under your control), would be to use JSON to take the guesswork out of formatting.  That is to say, convert the array of IDs to a JSON string before storing it in the text variable, using a!toJSON(), and use a!fromJSON() to convert it back later when needed.  In this way you're not stuck implementing your own parsing routine for the array-turned-string.

8 replies

mikes0011
Brainy
October 6, 2021

I don't see anything particularly wrong with the posted code snippet (beyond certain code style nitpicks).  One important thing to note is that your "refreshOnVarChange" is unnecessary as it's redundant; all a!localVariables() variables automatically have "refreshOnReferencedVarChange" set to TRUE by default unless overridden, so your local!employees variable would already refresh on any update to local!employeeIDs.  The same would be true for local!employeeIDs upon update to ri!record.employeeIDs.

Just to double check, what data type is ri!record.employeeIDs?  Are we assuming it's a single string of semicolon-separated ID values with no additional spaces in between?  I'm just checking because a common point of confusion around here arises from accidentally assuming Appian's default method of displaying an array of data in text (separated by semicolons) is equivalent to a semicolon-separated text list, even though these two things aren't direclty equivalent without some type-casting.

The Expression Guru
khabranp0001
October 6, 2021

Thanks for responding, Mike.

I agree with the redundancy, but it wasn't working without the refreshvariable, so I thought I would throw that in there.

The multiple values in the Text variable are as follows: "1; 2". I hope this helps. It looks as if the last value is not followed by a semicolon. Does this make any difference?