I am currently looking at using a number of APIs to improve data quality and reduce data entry where possible.
For example UK banks use two identifying characteristics,
Sort Code - which identifies the bank and branch, and
Account Number - which identifies the account (obvs).
Now from the Sort Code you can evaluate a range of useful information, such as Name of the Bank, Address of the Bank and the Telephone number. But more interestingly you can identify the BIC / SWIFT code and then identify the IBAN, which then makes international payments easier (as all of EU use IBAN and a growing number of non EU countries).
So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.
The challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.
Does anyone have any suggestions as to how to make it call the API before the form is saved?
REST as a validation mechanism
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
I'm SeanBenHayat wrote:David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
No I've not got that sophisticated yet. If you have the Sort Code then it should be populating everything from that. Essentially it is a single lookup to retrieve a json file of multiple records.
Re: REST as a validation mechanism
Sorry Sean, when you were talking about UK, I think we have a developer there by the name of David and I made the mistake.PointsWell wrote:I'm SeanBenHayat wrote:David, are these calls, cascading calls, meaning the user selection from one call affect the filtering on the next call?
If not, does it make sense to pre fetch them into a persistent or none-persistent tables before the form starts?
No I've not got that sophisticated yet. If you have the Sort Code then it should be populating everything from that. Essentially it is a single lookup to retrieve a json file of multiple records.
If it is a one time call, I'd stage that form into two parts ( I know it would look cheesy, as we should be able to make REST calls in rules too). The first part to gather the code, save it in user object, run a process to save the data in a none-persistent object (be sure all this happens under the umbrella of ONE process, so the data will stay alive for your second form), then in the second form you can use the data object returned as drop down or however you want to use.
Not an elegant approach. but it might work.
Re: REST as a validation mechanism
Is it not possible to start the REST process from an object rule that triggers the process. Also, have the object rule set to dynamic so it's triggered by some attribute recalculation on the formThe challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
Nope. You can trigger a process to call the service but only on save and not dynamically.ACDC wrote:Is it not possible to start the REST process from an object rule that triggers the process. Also, have the object rule set to dynamic so it's triggered by some attribute recalculation on the formThe challenge:
You cannot REQUEST SERVICE from a business rule, which is essentially where you'd need to trigger it.
Re: REST as a validation mechanism
I seem to recall there was trick to do this, but now that I think of it, it may have been an Applicability rule on the form that i was thinking ofNope. You can trigger a process to call the service but only on save and not dynamically.
Re: REST as a validation mechanism
Ah, EDI such fond memories.PointsWell wrote: So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.
I said it before (see https://www.awareim.com/forum/viewtopic.php?f=1&t=10324) and I will say it again: you can use a java plug-in for this.
Yes, plug-ins require more work
Yes, if you do not know java, you have to find someone else to create it
Yes, if you do not know java and the plug-in needs to be changed sometime in the future, you have to hope the creator is still around.
but, barring a better solution, plug-ins work. From the post in the link above, I created a simple BSV and plug-in. The plug-in makes a REST call to validate a VAT and is executed from the BO rules and dynamically updates the form.
Bob
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
Bunch of questions:BobK wrote:Ah, EDI such fond memories.PointsWell wrote: So far so good, except that I'd like to dynamically add all of this information while the user is keying in the form. Why, would I do that if the information is all available elsewhere? Because the EICSD where it comes from is borne from EDI standards from mainframe times and sometimes will split a bank name or address in a less than optimal manner. Therefore I'd like to capture the data on the form while the user is keying it in allowing them to tidy up the single source of truth data.
I said it before (see https://www.awareim.com/forum/viewtopic.php?f=1&t=10324) and I will say it again: you can use a java plug-in for this.
Yes, plug-ins require more work
Yes, if you do not know java, you have to find someone else to create it
Yes, if you do not know java and the plug-in needs to be changed sometime in the future, you have to hope the creator is still around.
but, barring a better solution, plug-ins work. From the post in the link above, I created a simple BSV and plug-in. The plug-in makes a REST call to validate a VAT and is executed from the BO rules and dynamically updates the form.
If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
Re: REST as a validation mechanism
What is your background? Do you know any other computer languages?PointsWell wrote: If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
I have a degree in computer science, but taught myself java. Mostly from "the really big index" https://docs.oracle.com/javase/tutorial ... index.html
There are also many other java tutorials and other information on the web.
I can give you the plug-in I created. It may not be the best tool for learning java, but it does have all the java methods required by AwareIM.
Bob
Re: REST as a validation mechanism
Hi Bob.
If you wouldn't mind I'd love to see your plugin too.
If you wouldn't mind I'd love to see your plugin too.
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
I can read code and understand generally what is going on. I’ve managed to write a bit of JS in Wavemaker. It would be great if you could share an example as it would give me a gauge of whether I know what’s going on or whether it’s over my head.BobK wrote:What is your background? Do you know any other computer languages?PointsWell wrote: If you don’t speak Java, how long would you be looking at to figure it out?
Is it something that if you had a template or an existing example you could figure out?
Probably more but can’t think at the moment. Too early.
I have a degree in computer science, but taught myself java. Mostly from "the really big index" https://docs.oracle.com/javase/tutorial ... index.html
There are also many other java tutorials and other information on the web.
I can give you the plug-in I created. It may not be the best tool for learning java, but it does have all the java methods required by AwareIM.
Don’t tell my alma mater - I technically have a degree in IT but I tend to keep it a secret.
Re: REST as a validation mechanism
Attached is my sample plug-in.
Read the included readme.txt file
Read the included readme.txt file
- Attachments
-
- ValidateVAT.zip
- (41.72 KiB) Downloaded 774 times
Bob
-
- Posts: 1460
- Joined: Tue Jan 24, 2017 5:51 am
- Location: 'Stralya
Re: REST as a validation mechanism
Thanks Bob.BobK wrote:Attached is my sample plug-in.
Read the included readme.txt file
What you've sent me is straightforward and I can figure out what is going on here (i.e. I think I can crib it to use other needs)
So using the website's example this returns:
Code: Select all
=====================
{"valid":true,"database":"ok","format_valid":true,"query":"LU26375245","country_code":"LU","vat_number":"26375245","company_name":"AMAZON EUROPE CORE S.A R.L.","company_address":"5, RUE PLAETIS\nL-2338 LUXEMBOURG"}
=========================
Re: REST as a validation mechanism
Glad I could help.
This is how I would do it if you wanted to populate fields with company_name, company_address and country_code:
Change the plug-in to return a String instead of a Boolean then parse the string returned from the service to create a string like the following
"AMAZON EUROPE CORE S.A R.L. # 5, RUE PLAETIS\nL-2338 LUXEMBOURG # LU"
and return that to AwareIM
In AwareIM:
Change the call to the plug-in to
VAT.Temp=ValidateVAT(SystemSettings.AccessKey,VAT.VAT)
add the following rules and attributes to the VAT BO
VAT.Company=REPLACE_PATTERN(VAT.Temp, '#.*$' '') // removes the first # and everything after it
VAT.Country=REPLACE_PATTERN(VAT.Temp, '^.*#' '') // removes everything from the beginning to the last #
VAT.Address=REPLACE_PATTERN(REPLACE_PATTERN(VAT.Temp, '^.*?#' ''), '#.*$', '') // removes everything but the address in the middle
NOTE: I have not tested the regular expressions for the REPLACE_PATTERN, so they may need some tweaking.
Correct, you will have to parse the string returned from the service and I would do as much parsing in the plug-in as possible. There are several java libraries for parsing JSON that should help, search the web for: java json. Since functions can only return 1 field, you will have to do some parsing inside AwareIM.PointsWell wrote:Presumably to then consume the string output it is 'just' a matter of parsing out everything from that string? Or is there an easier way to use the JSON?Code: Select all
===================== {"valid":true,"database":"ok","format_valid":true,"query":"LU26375245","country_code":"LU","vat_number":"26375245","company_name":"AMAZON EUROPE CORE S.A R.L.","company_address":"5, RUE PLAETIS\nL-2338 LUXEMBOURG"} =========================
This is how I would do it if you wanted to populate fields with company_name, company_address and country_code:
Change the plug-in to return a String instead of a Boolean then parse the string returned from the service to create a string like the following
"AMAZON EUROPE CORE S.A R.L. # 5, RUE PLAETIS\nL-2338 LUXEMBOURG # LU"
and return that to AwareIM
In AwareIM:
Change the call to the plug-in to
VAT.Temp=ValidateVAT(SystemSettings.AccessKey,VAT.VAT)
add the following rules and attributes to the VAT BO
VAT.Company=REPLACE_PATTERN(VAT.Temp, '#.*$' '') // removes the first # and everything after it
VAT.Country=REPLACE_PATTERN(VAT.Temp, '^.*#' '') // removes everything from the beginning to the last #
VAT.Address=REPLACE_PATTERN(REPLACE_PATTERN(VAT.Temp, '^.*?#' ''), '#.*$', '') // removes everything but the address in the middle
NOTE: I have not tested the regular expressions for the REPLACE_PATTERN, so they may need some tweaking.
Bob