I think it is not going to work using record exists, instead i have test another code and it worked, below is the code, we will simply find another existing email that has the same name and its status is Sent and then get the body of both existing and current email record, then will do a string replace and string match to remove the img tag from both bodies and then if the length of both bodies is equals we proceed to delete the record.
I have tested this and worked give it a ago and let me know what you think.
PHP Code:
// find an existing email with the same name and status is Sent
$emailId = record\findOne('Email', 'createdAt', 'desc', 'name=', name, 'status=', 'Sent');
// Get the body field
$body = record\attribute('Email', $emailId, '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)
);
Comment