Run integration only when users clicks a button on interface

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

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

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

  • 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.

  • 0
    Certified Lead Developer
    in reply to nancyb0004

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

  • Absolutely!  

    a!localVariables(
      
      
      local!integrationResponse: rule!UWM_POST_Calculate(
        caseId: ri!caseId,
        updatedByUserId:  rule!UWM_Get_User_Id(username: ri!loggedInUserVar),
        updatedByUserFullName:rule!UWM_Get_Full_Name(user: ri!loggedInUserVar),
      ),
      /* Extract the result from the body dictionary */
      local!result: index(local!integrationResponse, "body.result", false),
    
    
      /* Return the appropriate type based on the result */
      if(
        local!result,
        local!result,
        false
      )
    )

  • 0
    Certified Lead Developer
    in reply to nancyb0004

    OK. That name "UWM_Post_Calculate" points to an integration that might have been configured to "Modify Data". If this is true, and that integration does NOT modify any data, I suggest to change that configuration to "Queries Data" and this should just work.

Reply Children