Skip to main content
February 28, 2025
Question

Run integration only when users clicks a button on interface

  • February 28, 2025
  • 6 replies
  • 0 views

I have a scenario where the users is viewing an interface from a record action.   Before they click submit to complete the record action I want them to click a button that will call an integration and that value returned will either allow them to submit or not (it is a backend validation process).   Everything I am trying I run into issues because the refresh variable.


The code: 

a!localVariables(
  local!loggedInUserVar:fn!loggedInUser(),

  local!isLoading: false,
  local!isValid: a!refreshVariable(
    value: if(
      local!isLoading,
     
            rule!UWM_Map_Calculate_Data(
            caseId: ri!case.caseId,
            loggedInuserVar: local!loggedInUserVar
        
        ),
     
      false
    ),
    refreshOnVarChange: local!isLoading,
    refreshAlways: true,
   
  ),
 
  a!columnsLayout(
    columns: {
      a!columnLayout(
        contents: {
          a!sectionLayout(
            contents: {
              a!cardLayout(
                contents: {
                  a!buttonArrayLayout(
                    buttons: {
                      a!buttonWidget(
                        label: "Button",
                        icon: "check-double",
                        style: "OUTLINE",
                        saveInto: {
                          a!save(local!isLoading, true) /* Start loading state */
                        },
                        disabled: local!isLoading /* Disable button while loading */
                      )
                    },
                    align: "START",
                    marginBelow: "NONE"
                  ),
                }
              )
            },
          ),
        },
        width: "MEDIUM_PLUS"
      )
    },
    spacing: ""
  )
)


And the error on button click:  Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error in rule 'uwm_map_calculate_data': An error occurred when creating local!integrationResponse. a!save() and smart service functions cannot be used in a local variable unless "refreshAlways" is true for that local variable using the a!refreshVariable() function.

I've tried multiple different ways of achieving this but it always keeps coming back to this error.   Any suggestions on fixing this code OR achieving this in another way would be greatly appreciated

6 replies

stefanhelzle0001
February 28, 2025

Why not just call that integration inside the saveInto of that button? There is no need to complicate things with this local variables construct.

February 28, 2025

I've tried that 

a!localVariables(
  local!loggedInUserVar: fn!loggedInUser(),
  local!isLoading: false,
  local!isValid: false,
  a!sectionLayout(
    contents: {
      a!cardLayout(
        contents: {
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "Button",
                icon: "check-double",
                style: "OUTLINE",
                saveInto: {
                  a!save(local!isLoading, true)/* Start loading state */,
                  a!save(
                    local!isValid,
                    rule!UWM_Map_Calculate_Data(
                      caseId: ri!case.caseId,
                      loggedInuserVar: local!loggedInUserVar
                    ),
                    
                  )
                },
                disabled: local!isLoading/* Disable button while loading */
                
              )
            },
            align: "START",
            marginBelow: "NONE"
          ),
          {
            a!richTextDisplayField(
              labelPosition: "COLLAPSED",
              value: a!richTextItem(
                text: { fn!tostring(local!isValid) },
                style: "STRONG"
              ),
              
            )
          }
        }
      )
    },
    
  ),
  
)


and when I click the button I get this error:

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error [evaluation ID = 38a99:55128] : An error occurred while executing a save: Expression evaluation error in rule 'uwm_map_calculate_data': An error occurred when creating local!integrationResponse. a!save() and smart service functions cannot be used in a local variable unless "refreshAlways" is true for that local variable using the a!refreshVariable() function.

stefanhelzle0001
February 28, 2025

What is this expression doing? Can you share the code?