petercawdron
Kilo Guru

Recently, I ran into a problem where inbound email action criteria weren't working, even though I was very careful in how I set the criteria and tried stripping out anything overly complex. I just could not get criteria to work. When I examined the logic by writing the email subject and body to the system logs, I discovered something every peculiar.

 find_real_file.png

Those two lines should evaluate to be exactly the same, but...

find_real_file.png

There's some kind of pseudo space in the subject! If I type "Employee change" the result is -1 (ie, not found). If I copy and paste "Employee change" it's found, so something bizarre is happening in what should be plain text (and killing my criteria).

The solution I came up with was to handle the criteria in a script rather than in the filter and use JSON.stringify to convert these pseudo spaces into actual spaces so the evaluation would work properly.

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

	var eBody    = JSON.stringify(email.body_text).replace(/(\r\n|\n|\r)/gm,"");//get rid of line breaks
	var eSubject = JSON.stringify(email.subject);//convert dodgy pseudo spaces into actual spaces
	
	//the regular inbound email conditions can be a bit flakey so we'll handle our conditions in a script so we retain full control
	if(
		eSubject.indexOf('Employee change')!=-1 &&
		eBody.indexOf('whatever')!=-1 &&
		eBody.indexOf('something-else-unique')!=-1 &&
		eBody.indexOf('some-other-unique-detail')!=-1 
	){

		//Whatever action you want to take goes here...

		//No further event processing
		event.state="stop_processing";	
	}

})(current, event, email, logger, classifier);

I hope this helps someone else.

Cheers,

Version history
Last update:
‎10-24-2019 11:48 PM
Updated by: