Requirement is I will be entering emailaddresses on UI and it will be passed to the integration and the integration will return the emailAddresses with GUIDs . If any emailaddress is missing from the response which we entered then it must show that emailaddress on UI. Suppose I have passed test@test.com and test2@test.com and In repsonsed I get only GUID of only one emailaddress then it has to show the 2nd emailaddress on the UI as invalid error . How Can I achieve it
Discussion posts and replies are publicly visible
a!forEach( pv!jsonPv, if( contains(pv!emailPv, fv!item.emailAddress), {}, "This one is invalid: " & fv!item.emailAddress ) )
Mike Schmitt It is filtering correct emailaddress instead id incorrect emails .In API response i will get GUIDs of correct emailaddress . I need to show the one's without GUIDs on UI
Then you can replace the code in line 4 to check for any condition you need. I'm not exactly sure what you're saying you need, without some more detailed context and/or example outputs and logic, but it should be pretty simple to check each return line item for any condition you want and filter what you need it to.
So in this case you simply need to adjust where and how you filter. Assuming you have access to the original list of email addresses as well as the API response, you simply iterate through all original email addresses and check whether that address was mentioned in the API response values, and if not, return it as an "invalid" one.
a!localVariables( local!initialEmailAddressList: { "test1@test.com", "test2@test.com", "testInvalid@test.com", "test3@test.com" }, local!simulatedApiFeedback: { a!map( email: "test1@test.com", uuid: "asdf1234QWER" ), a!map( email: "test2@test.com", uuid: "asdf1234QWER" ), a!map( email: "test3@test.com", uuid: "asdf1234QWER" ) }, /* get any invalid email addresses by comparing the original list with the API feedback list */ a!flatten(a!forEach( local!initialEmailAddressList, if( contains( local!simulatedApiFeedback.email, fv!item ), {}, fv!item ) )) )
a!flatten(a!forEach( pv!EmailPV, ---TEXT FIELD if( contains( pv!JsonPv, fv!item ), --JSONPV -- MAP {}, fv!item )))
Getting the below error in script task .can you please help
ZAINAB said:contains( pv!JsonPv, fv!item ),
Why would "pv!JsonPv" contain the email address? pv!JsonPv is a map, not a string. Did you try "contains(pv!JsonPv.emailAddress, fv!item)"? My example code above clearly showed that the "contains()" call should check the list of map properties, not the map itself.
I tried it but it is showing correct emails also in invalidemails
You should create it as an Expression Rule (that you will then call from your process script task) and recreate the inputs and test it - that's far easier than trying it directly in a process and struggling to understand why it fails in a running process.
Feel free to post the code and your test input values here if you have a hard time getting it working.
a!localVariables( local!data:ri!Tasr_Requests, local!rawEmails: ri!Tasr_Requests.emailAddresses, 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: a!json({joinarray(local!individualEmails, ",")}),*/ local!formattedEmailString: ( joinarray(local!individualEmails, ",") ), local!validationMessage: if( a!isNotNullOrEmpty(local!invalidEmails), "Emails must be valid and each on a new line.", {} ), local!integrationResult:a!refreshVariable( value: if( a!isNullOrEmpty(local!invalidEmails), rule!Tasr_bulkgetemployees( emails:local!formattedEmailString, onSuccess:{}, onError:{} ), {}, ), refreshalways: true() ), a!formLayout_25r1( label: "Production Validation 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!Tasr_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!Tasr_Requests.startDate, save!value) }, required: true, requiredMessage: "Start Date is Required", validations: rule!Tasr_startDateValidation(ri!Tasr_Requests.startDate) ), a!dateField( label: "End Date", labelPosition: "JUSTIFIED", value: ri!Tasr_Requests.endDate, saveInto: { a!save(local!data.endDate, save!value), a!save(ri!Tasr_Requests.endDate, save!value) }, required: true, requiredMessage: "End Date is Required", validations: rule!Tasr_endDateValidation( ri!Tasr_Requests.startDate, ri!Tasr_Requests.endDate ) ) } ), a!columnLayout( contents: { a!textField( label: "Requested By:", labelPosition: "JUSTIFIED", value: rule!GBL_displayUserFirstLast(loggedInUser()), saveInto: ri!Tasr_Requests.requestorName, readOnly: true() ), a!textField( label: "Requestor Email:", labelPosition: "JUSTIFIED", value: loggedInUser(), saveInto: ri!Tasr_Requests.requestorEmail, readOnly: true(), validations: {} ), a!dateTimeField( label: "Requested On:", labelPosition: "JUSTIFIED", value: now(), saveInto: ri!Tasr_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!data.emailAddresses, save!value), a!save( ri!Tasr_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. ", {} ) ), a!cardLayout( contents: { /*a!richTextDisplayField(*/ /*labelPosition: "COLLAPSED",*/ /*value: {*/ /*a!richTextIcon(*/ /*icon: "info-circle",*/ /*caption:"",*/ /*color: "#0000ff",*/ /*size: "MEDIUM"*/ /*),*/ a!textField( label: "error", value: ri!InvalidEmail, ) }, align: "CENTER", showWhen: ri!HasError=true(), style: "INFO", marginAbove: "NONE", marginBelow: "LESS", accessibilityText: "Information message" ), }, style: "#134f5c", marginBelow: "STANDARD" ) } ) } ) } ) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidget_23r3( label: "Submit", style: "PRIMARY", submit: true, validate: true(), saveInto: { a!save(ri!TASR_Requests.emailAddresses,local!formattedEmailString), a!startProcess( processmodel:cons!Tasr_WRITE_REQUESTS, processParameters: { Emails:local!formattedEmailString }, ), a!save( ri!Tasr_Requests.requestorName, rule!GBL_displayUserFirstLast(loggedInUser()) ), a!save( ri!Tasr_Requests.requestorEmail, loggedInUser() ), a!save(ri!Tasr_Requests.createdOn, now()), a!save( ri!Tasr_Requests.requestStatus, cons!Tasr_AUDIT_STATUS_TYPES[1] ), a!save( ri!Tasr_Requests.requestType, cons!Tasr_REQUEST_TYPE ), a!save(ri!Tasr_Requests.isActive, true()), /*a!save(ri!Tasr_Requests.employeeIDs,index(ri!Result.body,"values",null()))*/ }, loadingIndicator: true() ) }, secondaryButtons: { a!buttonWidget_23r3( label: "Cancel", style: "NORMAL", submit: true, validate: false, value: true, saveInto: ri!cancel ) } ) ) )
If i create expressionrule then we would need data to be stored but as per the requirement it shold be stored only when there is no invalid emails . if any invalid emails then again show it on UI (3rd Xor)
ZAINAB said:If i create expressionrule then we would need data to be stored but as per the requirement it shold be stored only when there is no invalid emails
I'm not sure what you mean. An expression rule doesn't "store" anything that the process instance isn't already storing. Your expression rule should mirror (almost exactly) the code in your script task (only) and accept the email list and the JSON list as inputs, and should output only your "invalid email address".
For expression rule ,doesn't it required to call data from DB ?please let me know how can I create expressionrule and how to pass those process variable
ZAINAB said:For expression rule ,doesn't it required to call data from DB ?
Absolutely not - expression rules can handle any arbitrary input data, almost exactly like a script task in a process model would (but much easier to edit and test). You would just pass in your PV data and have it do whatever complex processing you need, and save the output to a PV (just like you do in your script task).
Have you taken the online Appian training? Knowing how to use expression rules is ABSOLUTELY CRITICAL in effective Appian development.
ZAINAB said:how can I create expressionrule
various ways - the "official" way is you go to your application object and click "create" -> "expression rule". However for quick testing you can create a new/unsaved expression rule simply by going to "yourenvironmenturl.com/suite/design/rule", which will load the (blank) expression rule editor.