Skip to main content
leonclintonc0001
January 25, 2022
Solved

Error in submitting data via an Interface in a Site

  • January 25, 2022
  • 11 replies
  • 0 views

I have created an application that uses a public API as an Integration to retrieve the required data from a 3rd party website and store it in the Appian database.

So my application is a "Dictionary Book" and I have created a CDT for the same using these fields:  

id
word
phonetic
origin
definition
example
searchedBy
searchedAt

Next, I created an interface wherein I have passed this CDT, readOnly and cancel as a rule input. The user needs to fill and submit the "word" field, and the "searchedBy" and "searchedAt" fields are set using loggedInUser and now function. The rest of the fields would get their respective data via Integrations.

I created the entire process in the Process Model and I was able to get and save the data for all the CDT fields without any errors.

But when I added this interface as a page to my site, and tried to execute this interface, it gave me an error saying:

Expression evaluation error [evaluation ID = 831a9:498d4] in rule 'lcp_searchwordv1' : An error occurred while executing a save: Expression evaluation error: The save target must be a local variable that does not refresh on every evaluation or on an interval, a process variable, or a node input (or a rule input passed one of those three), but instead was: [id=, word=, phonetic=, origin=, definition=, example=, searchedBy=, searchedAt=]

 

I have attached the code for the interface as well. Please help me to resolve this issue

a!localVariables(
  local!username: loggedInUser(),
  local!time: now(),
  local!main: ri!dictionaryV1.word,
  a!formLayout(
    label: "",
    contents: {
      a!richTextDisplayField(
        labelPosition: "COLLAPSED",
        value: {
          a!richTextItem(
            text: {
              a!richTextIcon(
                icon: "book"
              ),
              " Free Dictionary Search"
            },
            color: "#4cb020",
            size: "LARGE",
            style: {
              "STRONG"
            }
          )
        },
        marginBelow: "MORE"
      ),
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!textField(
                label: "Search a Word",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                instructions: "",
                helpTooltip: "Make sure the Entered Word is Valid",
                placeholder: "---  Enter the word to be searched in the Dictionary  ---",
                value: local!main,
                saveInto: local!main,
                characterLimit: 255,
                showCharacterCount: false,
                required: true,
                readOnly: ri!readOnly
              ),
              a!pickerFieldUsers(
                label: "User Name",
                labelPosition: "ABOVE",
                instructions: "If your name is not displayed / unavailable, please contact your Branch Supervisor",
                maxSelections: 1,
                value: local!username,
                saveInto: local!username,
                showWhen: or(
                  isnull(ri!readOnly),
                  ri!readOnly=false()),
                required: true,
                disabled: false,
                validations: {}
              ),
              a!textField(
                label: "Origin",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: {},
                saveInto: {},
                characterLimit: 255,
                showCharacterCount: false,
                showWhen: ri!readOnly = true(),
                readOnly: ri!readOnly
              ),
              a!textField(
                label: "Example",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: {},
                saveInto: {},
                characterLimit: 255,
                showCharacterCount: false,
                showWhen: ri!readOnly = true(),
                readOnly: ri!readOnly
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!textField(
                label: "Language Selected",
                labelPosition: "ABOVE",
                instructions: "The system selects ""English"" as the Default Language for all searches",
                value: "English",
                saveInto: {},
                refreshAfter: "UNFOCUS",
                required: true,
                disabled: true,
                validations: {}
              ),
              a!dateTimeField(
                label: "Date & Time",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: local!time,
                saveInto: local!time,
                required: true,
                readOnly: ri!readOnly,
                disabled: false
              ),
              a!textField(
                label: "Phonetic",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: {},
                saveInto: {},
                characterLimit: 255,
                showCharacterCount: false,
                showWhen: ri!readOnly = true(),
                readOnly: ri!readOnly
              ),
              a!textField(
                label: "Definition",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: {},
                saveInto: {},
                characterLimit: 255,
                showCharacterCount: false,
                showWhen: ri!readOnly = true(),
                readOnly: ri!readOnly
              ),
              a!textField(
                label: "Searched By",
                labelPosition: if(
                  ri!readOnly,
                  "ADJACENT",
                  "ABOVE"
                ),
                value: ri!dictionaryV1.searchedBy,
                saveInto: ri!dictionaryV1.searchedBy,
                characterLimit: 255,
                showCharacterCount: false,
                showWhen: ri!readOnly = true(),
                readOnly: ri!readOnly
              )
            }
          )
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Search",
          saveInto: {
            a!save(target: ri!dictionaryV1.searchedBy, value: local!username),
            a!save(target: ri!dictionaryV1.searchedAt, value: local!time),
          },
          submit: true,
          style: "PRIMARY"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      },
      showWhen: or(
        isnull(
          ri!readOnly
        ),
        not(
          ri!readOnly
        )
      )
    )
  )
)  

Best answer by csteward

Hi, by default, variables defined under a!localVariables() will attempt to refresh each time any referenced variables are changed, so your definition of local!main will throw this error when you attempt to save into it (it can be only one or the other, a refreshing variable, or a save-capable variable).

Change your definition to block refreshing such as below, and you should be all set:

a!localVariables(
  local!username: loggedInUser(),
  local!time: now(),
  local!main: a!refreshVariable(
    value: ri!dictionaryV1.word,
    refreshAlways: false
  ),
  .
  .
  .
)

11 replies

csteward
cstewardAnswer
January 25, 2022

Hi, by default, variables defined under a!localVariables() will attempt to refresh each time any referenced variables are changed, so your definition of local!main will throw this error when you attempt to save into it (it can be only one or the other, a refreshing variable, or a save-capable variable).

Change your definition to block refreshing such as below, and you should be all set:

a!localVariables(
  local!username: loggedInUser(),
  local!time: now(),
  local!main: a!refreshVariable(
    value: ri!dictionaryV1.word,
    refreshAlways: false
  ),
  .
  .
  .
)

leonclintonc0001
January 25, 2022

Hey Chris, I added this snippet to my code, but its giving me the same error as before on my site

csteward
January 25, 2022

Just to confirm, is this error appearing when you type into the "Search a word" field, or when completing a different action?