How to call integration in interface

 


t

= a!localVariables(
  local!data: ri!_Requests,
  local!errorMessage: "test",
  local!result,
  local!emails: ri!_Requests.emailAddresses,
  local!integration,
  local!individualMail: if(
    a!isNullOrEmpty(local!emails),
    {},
    reject(
      fn!isnull(_),
      split(local!emails, char(10))
    )
  ),
  local!invalidEmails: substitute(
    tostring(
      reject(
        fn!isnull(_),
        a!forEach(
          items: local!individualMail,
          expression: if(
            regexmatch(
              pattern: "^s[A-Z0-9\_-]+(\.{0,1}[A-Z0-9\+_-]+)*[@]{1}[A-Z0-9.-]*[A-Z0-9-]+[.]{1}[A-Z]{2,6}$",
              searchString: fv!item,
              regexFlags: "si"
            ),
            null,
            fv!index
          )
        )
      )
    ),
    ";",
    ","
  ),
  local!validation: if(
    isnull(local!invalidEmails),
    {},
    "Emails must be in a valid format, and each email must be on a new line. "
  ),
  a!formLayout(
    label: "Request",
    contents: {
      a!sectionLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!boxLayout(
                    label: "",
                    labelSize: "SMALL",
                    contents: {
                   
                      a!paragraphField(
                        label: "Email Addresses",
                        labelPosition: "JUSTIFIED",
                        placeholder: "Email Addresses should be one per line (can be pasted from Excel)",
                        value: local!data.emailAddresses,
                        saveInto: {
                         rule!_bulkgetemployees(
                            "Emails":"test@test.com",
                          ),
                          a!save(local!data.emailAddresses, save!value),
                          a!save(
                            ri!_Requests.emailAddresses,
                            save!value
                          )
                        },
                        refreshAfter: "KEYPRESS",
                        height: "TALL",
                        required: true,
                        requiredMessage: "Email Address is Required",
                        validations:if(
                          (a!isNotNullOrEmpty(local!invalidEmails)),
                          "Emails must be in a valid format, and each email must be on a new line. ",
                          {}
                        )
                      )
                     
                    },
                    style: "#134f5c",
                    marginBelow: "STANDARD"
                  )
                }
              )
            }
          )
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget_23r3(
          label: "Submit",
          style: "PRIMARY",
          submit: true,
          validate: true(),
          saveInto: {
            a!save(
              ri!_Requests.requestorName,
              rule!GBL_displayUserFirstLast(loggedInUser())
            ),
            a!save(
              ri!_Requests.requestorEmail,
              loggedInUser()
            ),
            a!save(ri!_Requests.createdOn, now()),
            a!save(
              ri!_Requests.requestStatus,
              cons!_AUDIT_STATUS_TYPES[1]
            ),
            a!save(
              ri!_Requests.requestType,
              cons!_REQUEST_TYPE
            ),
            a!save(ri!_Requests.isActive, true()),
           
          },
          loadingIndicator: true()
        )
      },
      secondaryButtons: {
        a!buttonWidget_23r3(
          label: "Cancel",
          style: "NORMAL",
          submit: true,
          validate: false,
          value: true,
          saveInto: ri!cancel
        )
      }
    )
  )
)




I need validation in such a way that it validates each mail address is in mail format and one mail address per line.
example : "test@test.com"
"test2@test.com"

If there are any errors then throw validation error ,if all email addresses are in mail format then how to pass these mailaddresses to integration where body is

"emails": "test@test.com, test@test.com" and save the response of this mailsaddress in DB 

  Discussion posts and replies are publicly visible

Parents Reply Children
  • a!localVariables(
      local!data:ri!ASR_Requests,
      local!rawEmails: ri!ASR_Requests.emailAddresses,
      
      local!integrationResult,
      local!isintegrationSuccess,
    
      local!individualEmails: reject(
        a!isNullOrEmpty(_),
        a!forEach(
          items: split(local!rawEmails, char(10)),
          expression: trim(fv!item)
        )
      ),
    
      local!invalidEmails: reject(
        a!isNullOrEmpty(_),
        a!forEach(
          items: local!individualEmails,
          expression: if(
            regexmatch(
              pattern: "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$",
              searchString: fv!item,
              regexFlags: "si"
            ),
            null,
            fv!item
          )
        )
      ),
    
      local!formattedEmailString: joinarray(local!individualEmails, ", "),
    
      local!validationMessage: if(
        a!isNotNullOrEmpty(local!invalidEmails),
        "Emails must be valid and each on a new line.",
        {}
      ),
      a!formLayout(
        label: "Test Request",
        contents: {
          a!sectionLayout(
            contents: {
              a!columnsLayout(
                columns: {
                  a!columnLayout(
                    contents: {
                      a!boxLayout(
                        label: "",
                        labelSize: "SMALL",
                        contents: {
                          a!columnsLayout(
                            columns: {
                              a!columnLayout(
                                contents: {
                                  a!textField(
                                    label: "Title:",
                                    labelPosition: "JUSTIFIED",
                                    value: local!data.requestTitle,
                                    saveInto: {
                                      a!save(local!data.requestTitle, save!value),
                                      a!save(
                                        ri!ASR_Requests.requestTitle,
                                        save!value
                                      )
                                    },
                                    refreshAfter: "KEYPRESS",
                                    characterLimit: 100,
                                    required: true,
                                    requiredMessage: "Title is Required"
                                  ),
    
                                  a!dateField(
                                    label: "Start Date",
                                    labelPosition: "JUSTIFIED",
                                    value: local!data.startDate,
                                    saveInto: {
                                      a!save(local!data.startDate, save!value),
                                      a!save(ri!ASR_Requests.startDate, save!value)
                                    },
                                    required: true,
                                    requiredMessage: "Start Date is Required",
                                    validations: rule!ASR_startDateValidation(ri!ASR_Requests.startDate)
                                  ),
    
                                  a!dateField(
                                    label: "End Date",
                                    labelPosition: "JUSTIFIED",
                                    value: ri!ASR_Requests.endDate,
                                    saveInto: {
                                      a!save(local!data.endDate, save!value),
                                      a!save(ri!ASR_Requests.endDate, save!value)
                                    },
                                    required: true,
                                    requiredMessage: "End Date is Required",
                                    validations: rule!ASR_endDateValidation(
                                      ri!ASR_Requests.startDate,
                                      ri!ASR_Requests.endDate
                                    )
                                  )
    
                                }
                              ),
                              a!columnLayout(
                                contents: {
                                  a!textField(
                                    label: "Requested By:",
                                    labelPosition: "JUSTIFIED",
                                    value: rule!GBL_displayUserFirstLast(loggedInUser()),
                                    saveInto: ri!ASR_Requests.requestorName,
                                    readOnly: true()
                                  ),
                                  a!textField(
                                    label: "Requestor Email:",
                                    labelPosition: "JUSTIFIED",
                                    value: loggedInUser(),
                                    saveInto: ri!ASR_Requests.requestorEmail,
                                    readOnly: true(),
                                    validations: {}
                                  ),
                                  a!dateTimeField(
                                    label: "Requested On:",
                                    labelPosition: "JUSTIFIED",
                                    value: now(),
                                    saveInto:  ri!ASR_Requests.createdOn, 
                                    readOnly: true(),
                                    validations: {}
                                  )
                                }
                              )
                            }
                          ),
                          a!paragraphField(
                            label: "Email Addresses",
                            labelPosition: "JUSTIFIED",
                            placeholder: "Email Addresses should be one per line (can be pasted from Excel)",
                            value: local!data.emailAddresses,
                            saveInto: {  
                              a!save(
                                local!integrationResult,
                                rule!ASR_bulkgetemployees(Emails: local!formattedEmailString)
                              ),
                              a!save(local!data.emailAddresses, save!value),
                              a!save( ri!ASR_Requests.emailAddresses, save!value)
                            },
                            refreshAfter: "KEYPRESS",
                            height: "TALL",
                            required: true,
                            requiredMessage: "Email Address is Required",
                            validations:if(
                              (a!isNotNullOrEmpty(local!invalidEmails)),
                              "Emails must be in a valid format, and each email must be on a new line. ",
                              {}
                            )
                          )
    
                        },
                        style: "#134f5c",
                        marginBelow: "STANDARD"
                      )
                    }
                  )
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget_23r3(
              label: "Submit",
              style: "PRIMARY",
              submit: true,
              validate: true(),
              saveInto: {
                a!save(
                  ri!ASR_Requests.requestorName,
                  rule!GBL_displayUserFirstLast(loggedInUser())
                ),
                a!save(
                  ri!ASR_Requests.requestorEmail,
                  loggedInUser()
                ),
                a!save(ri!ASR_Requests.createdOn, now()),
                a!save(
                  ri!ASR_Requests.requestStatus,
                  cons!ASR_AUDIT_STATUS_TYPES[1]
                ),
                a!save(
                  ri!ASR_Requests.requestType,
                  cons!ASR_REQUEST_TYPE
                ),
                a!save(ri!ASR_Requests.isActive, true())
    
              },
              loadingIndicator: true()
            )
          },
          secondaryButtons: {
            a!buttonWidget_23r3(
              label: "Cancel",
              style: "NORMAL",
              submit: true,
              validate: false,
              value: true,
              saveInto: ri!cancel
            )
          }
        )
      )
    )




    Here is my interface code where i want to check the emailaddress validation first and then pass those mails to the integration without clicking on submit .can you please help

  • 0
    Certified Lead Developer
    in reply to ZAINAB

    Did you look at the value of local!formattedEmailString before trying the integration, to see if it contains the value you expect?  I notice that the only time it's changed is upon form load, so it should already hold its correct value presumably before you interact with the paragraph field.

  • Yes,i'm getting the mails by comma seperated which is expected

  • 0
    Certified Lead Developer
    in reply to ZAINAB

    And if you copy out the exact same value and run it in the integration rule by itself, it works?

  • copied the value and pasted the value in the  " " in the integration it is working

  • 0
    Certified Lead Developer
    in reply to ZAINAB
    in the  " "

    does this mean the integration expects a slightly different value from what the local variable holds?  can you post some screenshots of the interface's current exact value and the value you're entering in the integration that's working?

  • Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error [evaluation ID = ab535:440c6] : An error occurred while executing a save: Expression evaluation error : An error occurred when creating local!integrationResult. 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.

    getting this error sometime 

  • 0
    Certified Lead Developer
    in reply to ZAINAB

    In case this makes any difference to your integration, these values are separated by a comma but not a space.  The values you're created in local!formattedString are separated by a comman AND a space.  This could easily make a difference if the integration is not expecting to clean extra spaces between emails.

  • It is not making any difference .There is some issue calling the integration from the rule .


    is this correct way to pass the body of the integration?
    a!save(
    local!integrationResult,
    rule!ASR_bulkgetemployees(Emails:local!formattedEmailString),
    ),

    with this code i get warning as invalid parameter.



    a!save(
    local!integrationResult,
    rule!ASR_bulkgetemployees({"Emails":local!formattedEmailString}),
    ),

    with this code it says Missing keyword syntax