record\exists() possible fiilters/operators
Collapse
X
-
Basically if I have
string1: "Test 1234 test 4567" and
string2: "Test 1234 test 4567"
then extract 'test' from string1 using RegEx I would get:
string1: "Test 1234 4567"
then I am using LIKE operator to compare if the whole string1 is part of the string2 -> it would return False, right?
I would have to extract 'test' and everything after it to be able to use LIKE operator that would return True. That is how the LIKE operator works, it is comparing if the whole string1 is part of the string2, looking for exactly same string sequence
Hopefully it is clearLast edited by Jakub Grufik; 05-05-2023, 12:14 PM. -
this regex also solved problem which would occur if there would be more than 1 attachment -
OK guys I have finally cracked it. But it is pretty hard to explain it
The problem was that it was extracting the image element from the body by using RegEx: /<img[^>]+attachment[^>]+>/ BUT there was still some content after that whole image element, so when I was comparing bodyWithoutImage and bodyWithImage by using LIKE operator. It was returning false because the whole bodyWithoutImage was not part of the bodyWithImage because the image element was just cut from the body, I needed to use a bit different RegEx to extract image element and everything after it and it is now working as expected.
Hopefully you will understand it from the screen
RegEx used to extract everything after image as well:
/<img[^>]+attachment.+/
Whole code:
Code:$archivedBodyCut = string\replace(body, string\match(body, '/<img[^>]+attachment.+/'), ''); $archivedBodyCutRegEx = string\concatenate('%', $archivedBodyCut, '%'); output\printLine(record\exists('Email', 'name=', name, 'body*', $archivedBodyCutRegEx, 'status=', 'Sent'))
I am pretty sure that I am explaining it like dum, so if it is not clear tell me and I will try to explain it a bit more
Thanks a lot for everything!Leave a comment:
-
For some reason it does not work with concat
Code:$archivedBodyCut = string\replace(body, string\match(body, '/<img[^>]+attachment[^>]+>/'), ''); output\printLine(record\exists('Email', 'name=', name, 'body*', string\concatenate('%', $archivedBodyCut, '%'), 'status=', 'Sent'));
Leave a comment:
-
yeah thats exactly what I have in the topic above, I am going to try it. Thanks for help man -
string length just added a security to make sure that the body of both emails match, but if you feel ease to not use it then it should be fine. -
Hey mate,
Maybe this would work, using like operator and string replace + string match
PHP Code:$body = string\replace(body, string\match(body, '/<img[^>]+attachment[^>]+>/'), ''); ifThen(record\exists('Email', 'name=', name, 'body*', string\concatenate('%', $body, '%'), 'status=', 'Sent'), record\update('Email', id, 'deleted', true) );
Leave a comment:
-
Also this one could be working as expected:
Code:$archivedBodyCut = string\replace(body, string\match(body, '/<img[^>]+attachment[^>]+>/'), ''); $archivedBodyCutRegEx = string\concatenate('%', $archivedBodyCut, '%'); record\exists('Email', 'name=', name, 'body*', $archivedBodyCutRegEx, 'status=', 'Sent')
Leave a comment:
-
rabii thanks a lot for the workaround.
Seems like it is working as expected, I just needed to adjust regular expression a bit because there was img element at the beginning of the body as well and it matched regex so the one with attachment was not extracted.
Also I tried to compare $body1 and $body2 (both with extracted <img src="?entryPoint=attachment&id=6452a6557bbdec 88b" style="width: 25%;">) directly using $body1 == $body2, and it seems like it is working perfectly fine even without string\length.
What do you think?
Code:$sentId = record\findOne('Email', 'createdAt', 'desc', 'name=', name, 'status=', 'Sent'); $sentBody = record\attribute('Email', $sentId, 'body'); $sentBodyCut = string\replace($sentBody, string\match($sentBody, '/<img[^>]+attachment[^>]+>/'), ''); $archivedBodyCut = string\replace(body, string\match(body, '/<img[^>]+attachment[^>]+>/'), ''); output\printLine($sentBodyCut == $archivedBodyCut)
Thanks a lot for this workaround mate!
Now I am going to try to use string\concatenate to be able to use variable in record\exists() and its LIKE operator as yuri mentioned like this:
Code:$bodyCut = string\substring(body, 0, -100); record\exists('Email', 'name=', name, 'body*', string\concatenate('%', $bodyCut, '%'), 'status=', 'Sent')
Leave a comment:
-
'%' + $myVariable + '%' – this won't work.
String concatenation with + operator is not supported in Formula (unfortunately, we cannot implement it as it would be a backward compatibility break, as currently '20' + '10' converts strings to integer and applies summation operator.
You need to use string\concatenate function. -
You can also use record\exists to check first condition and then execute the code above, like below:
PHP Code:ifThen(record\exists('Email', 'name=', name, 'status=', 'Sent'), // find an existing email with the same name and status is Sent and get its body field $body = record\attribute('Email', record\findOne('Email', 'createdAt', 'desc', 'name=', name, 'status=', 'Sent'), 'body'); // compare the length of the two bodies using string\replace and string\match to remove the img tag ifThen(string\length(string\replace($body, string\match($body, '/<img[^>]+>/'), '')) == string\length(string\replace(body, string\match(body, '/<img[^>]+>/'), '')), record\update('Email', id, 'deleted', true) ); );
Leave a comment:
Leave a comment: