Felice_Vittoria | 2021-09-08 01:12:41 UTC | #1
I need to call a data action within a pre-call rule to determine whether or not to place a call. The 3rd party web service returns 3 pieces of data where I need to create conditions against and if any of the conditions is true then my action would be to do not dial. The same fields also exist in the contact list.
Is it possible to create conditional statements and based on those conditions return true/false within a response template? If so, how? Also, please let me know if you have any questions.
Thank you, Felice
Jason_Mathison | 2021-09-08 01:15:58 UTC | #2
Your best bet is to give a couple of examples of what the response from the endpoint would look like, one that should evaluate to true and one for false (and why, if it isn't totally clear).
Making this work would likely use the Apache Velocity syntax in the success template. https://velocity.apache.org/engine/1.7/user-guide.html
--Jason
Felice_Vittoria | 2021-09-08 13:19:44 UTC | #3
Jason,
Thanks. Here's an example response. I need to check to see if balance > 0, membershipstatus is not Cancelled or Suspended and dncflag = true.
{ "profile.phones.suffixNumber": [ "9832" ], "profile.phones.description": [ "CELL PHONE" ], "header.timestamp": "08 SEP 2021 - 09:16:21 am", "profile.membership.expirationDate": "2021-08-31", "profile.address.streetAddress1": "1234 Street", "profile.membership.RVOptionEnabled": "false", "profile.membership.membershipTier": "Plus", "profile.savings": "0.00", "profile.email": "hello@world.com", "profile.firstName": "FIRST", "profile.membership.membershipStatus": "Active", "profile.address.city": "CITY", "profile.lastName": "LAST", "profile.gender": "M", "profile.address.postalCode": "11111", "profile.phones.phoneType": [ "C" ], "profile.phones.exchangeNumber": [ "245" ], "profile.membership.memberSince": "2006-07-25", "profile.DNCFlag": "false", "profile.accrEnabled": "false", "profile.membership.ersAbuser": "false", "profile.dateOfBirth": "1901-01-01", "profile.address.streetAddress2": "", "profile.phones.extensionNumber": [ "" ], "profile.balance": "0.00", "profile.address.stateOrProvince": "TX", "profile.membership.membershipNumber": "12345", "profile.phones.areaNumber": [ "713" ] }
Thank you, Felice
Jason_Mathison | 2021-09-08 13:39:21 UTC | #4
Just to check, is this the actual response from the endpoint, or is this after a data action flattened it? If you are running this through a data action you can see the actual response in test mode in the "Execute" step.
--Jason
Felice_Vittoria | 2021-09-08 14:15:58 UTC | #5
Jason,
I modified some values in the response to not show actual customer information. Also, this is what I got with the Flatten Output enabled.
Thank you, Felice
Jason_Mathison | 2021-09-08 14:23:59 UTC | #6
Please provide an example that is not flattened, otherwise it will be hard to give you a working example. Replacing customer information with fake data is fine.
The tricky part of this is probably going to be dealing with the balance. Will a zero balance always be "0.00". Can there be a negative balance?
Felice_Vittoria | 2021-09-08 14:38:21 UTC | #7
Jason,
Correction on balance condition ... if it's equal to 0.00
Here's the unflattened output:
{ "header": { "timestamp": "08 SEP 2021 - 10:35:36 am" }, "profile": { "lastName": "LAST", "firstName": "FIRST", "gender": "F", "dateOfBirth": "1901-01-01", "balance": "0.00", "accrEnabled": "false", "savings": "0.00", "email": "hello@world.com", "DNCFlag": "false", "membership": { "membershipNumber": "12343", "membershipTier": "Plus", "RVOptionEnabled": "false", "membershipStatus": "Active", "expirationDate": "2021-08-31", "memberSince": "2006-07-25", "ersAbuser": "false" }, "address": { "streetAddress1": "123 Street", "streetAddress2": "", "city": "CITY", "stateOrProvince": "TX", "postalCode": "12345" }, "phones": [ { "phoneType": "C", "description": "CELL PHONE", "areaNumber": "713", "exchangeNumber": "111", "suffixNumber": "1111", "extensionNumber": "" } ] } }
Jason_Mathison | 2021-09-08 15:12:35 UTC | #8
Here is a first pass at this. It returns an output of "result" that is of type boolean.
{ "translationMap": { "balance" : "profile.balance", "membershipStatus" : "profile.membership.membershipStatus", "DNCFlag" : "profile.DNCFlag" }, "translationMapDefaults": {}, "successTemplate": "{\"result\" : #if($balance == \"${esc.q}0.00${esc.q}\" || $membershipStatus == \"${esc.q}Cancelled${esc.q}\" || $membershipStatus == \"${esc.q}Suspended${esc.q}\" || $DNCFlag == \"${esc.q}true${esc.q}\")true#{else}false#end}" }
Felice_Vittoria | 2021-09-08 15:12:34 UTC | #9
Thanks Jason! That worked for me! I am going to mark your post as a solution.
system | 2021-10-09 15:13:15 UTC | #10
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 11939