If you think that something doesn't work in Aware IM post your message here
#52288 by weblike
Fri Dec 06, 2019 3:23 pm
This topic is based on this post: https://www.awareim.com/forum/viewtopic.php?f=4&t=9026
I try to use REPLACE_PATTERN function with some attributes, but if one attribute is empty->the result of the function is empty attribute also.

For example:
Orders.CustomerFirstName = Jane
Orders.CustomerLastName = Doe

Creating another BO based on Orders.BO with these rules => the result is ok.
Rule 1:
Code: Select allIf Messages.HTML CONTAINS '{CustomerFirstName}' Then
Messages.HTML=REPLACE_PATTERN(Messages.HTML,'\{CustomerFirstName\}',Messages.Owner.Customer_FirstName)

Rule 2:
Code: Select allIf Messages.HTML CONTAINS '{CustomerLastName}' Then
Messages.HTML=REPLACE_PATTERN(Messages.HTML,'\{CustomerLastName\}',Messages.Owner.Customer_LastName)


BUT if one of the fields are empty => the result of REPLACE_PATERN is also empty
Orders.CustomerFirstName = 'Jane'
Orders.CustomerLastName = ''

https://streamable.com/3g3yf

Here is a sample BSV:
1. Create one Order (complete Customer First Name, Customer Last name)
2. Create a message template with both 2 tokens {CustomerFirstName} {CustomerLastName}
2. In Orders list query -> click "Create Message" button
==> inspect the result in "Messages" query (you should see the message with entered info in Orders attributes)
3. Edit the Order and empty one field
4. In Orders list query -> click "Create Message" button -->inspect the created message ->the result will be an empty field.
Attachments
(40.25 KiB) Downloaded 56 times
#52290 by Jaymer
Fri Dec 06, 2019 3:53 pm
i would say "look at the log"
you think its NOT firing, but it MUST be firing (the REPL)

and, make it easy on yourself (and more readable code), quit having to use the extra \ to escape the {

just make your insert tokens be !Fname! instead of {Fname}

the user doesn't care cause he is not even typing them in.
#52293 by weblike
Fri Dec 06, 2019 7:18 pm
Hello Jaymer,
I use the log viewer allt the time when I these kind of cases.
Changed the curly brackets with other annotations, not the problem here.
I think this is a bug. REPLACE_PATTERN should take empty field as '' and replace only the argument I set into it, not entire attribute.
Selection_999(131).png
Selection_999(131).png (61.6 KiB) Viewed 1069 times
#52295 by Jaymer
Fri Dec 06, 2019 7:33 pm
well thats simple

IF html contains !thetag! and replacement_value is DEFINED THEN
replace_pattern
#52296 by weblike
Fri Dec 06, 2019 7:56 pm
Jaymer wrote:well thats simple

IF html contains !thetag! and replacement_value is DEFINED THEN
replace_pattern


What you say leaves the !thetag! untouched =>the result is "Hello Jane !thetag! " ....and this involves an ELSE statement... Imagine in real life app I have at least 15-20 tokens to replace...
As described in source post I use this for Email Templates....which contains 2 attributes "Subject" & "Body"...that result 20 x 2 =40 IF's ELSE statements...
This should be kept simple and not give to the app not needed high consuming operations. REPLACE_PATTERN should deal with a simple '' .
#52297 by BobK
Fri Dec 06, 2019 8:27 pm
weblike wrote:I think this is a bug.


It is not a bug, it is a java feature :lol:

A lot of java functions return null if any of the parameters are null. I suspect that is what is happening here.

One solution is:
change your rules to
Code: Select allIf Messages.HTML CONTAINS '{CustomerLastName}' Then
Messages.HTML=REPLACE_PATTERN(Messages.HTML,'\{CustomerLastName\}',(Messages.Owner.Customer_LastName+'~'))


which is adding ~ to the replacement value so any null attribute is no longer null.
Note: your can use any character besides ~ as long it is not used anywhere else in the message.

Then add the following rule to remove all of the ~
Code: Select allIf Messages.HTML CONTAINS '~' Then
Messages.HTML=REPLACE_PATTERN(Messages.HTML,'~','')
#52298 by Jaymer
Fri Dec 06, 2019 8:40 pm
BobK wrote:It is not a bug, it is a java feature

LOL

Bobk, yes, that'll do it.
you are right George, I forgot about that. I wasn't thinking about that part being null - guess I didn't read it correctly (twice).
#52301 by weblike
Sat Dec 07, 2019 6:18 am
BobK wrote:It is not a bug, it is a java feature :lol:


LOL :lol: :lol: :lol:

Who is online

Users browsing this forum: No registered users and 8 guests