Perform smart rule trigger import event no longer works from within rules

Run externally from Script Editor, this script will trigger smart rules whose conditions are fulfilled by the selected records:

tell application id "DNtp"
	set theRecords to the selection
	repeat with theRecord in theRecords
		perform smart rule trigger import event record theRecord
	end repeat
end tell

Running the same script from within a smart rule, however, does nothing:

on performSmartRule(theRecords)
	tell application id "DNtp"
		set theRecords to the selection
		repeat with theRecord in theRecords
			perform smart rule trigger import event record theRecord
		end repeat
	end tell
end performSmartRule

Select a record for which a smart rule would trigger on import (the same record as used previously), select Apply Rules from the context menu, select above rule, and nothing happens. This used to work, and is essential to be able to trigger additional rules on records which are OCR’d by a rule. I have spent some time experimenting with this; rules which previously worked do not work any more. I’m not sure when this behaviour changed, but could it pls be changed back?

The Apply Rule action is actually recommended instead.

Yeah, I knew you would say that, but unfortunately that is only helpful if you know which rule needs to be triggered. I have a smart rule which performs OCR on any PDF with 0 words; those PDFs can come from multiple sources and previously were then dealt with by one of approx. 50 rules. I can’t even automatically determine which rule the PDF should be sent to before it has been OCR’d, as the rule conditions are routinely based on the contents of a record.

I’m guessing the functionality has been intentionally crippled to avoid trigger loops; but, to be quite honest, those who are writing scripts need to know what they are doing and be aware that they can cause damage; the delete command, for example, hasn’t been removed :wink:

Is there any way for me to work around this?

Famous last words :slight_smile: Anyway, I see your point and it should be possible to trigger the other rules to avoid loops. Will check this.

2 Likes

Thanks :slight_smile: I wonder whether a loop could be recognised (e.g. if a rule runs for the 10th time in x seconds, or if DT never returns to settled state or …), and the progress indicator opened (with the termination option) in such a case.

(I admit to having used slightly uncharitable words; I’ve just spent hours trying to figure out what I was doing wrong only to find that I’m just trying to use something no longer available :see_no_evil:)

1 Like

The rule which is executing the script should definitely not be triggered again.

That’s ideal. But currently no rule is being triggered; so if perform smart rule trigger import event record theRecord could be made to work again from inside a rule, all would be great.

The next release will support this again.

2 Likes

Thank you very much Criss :slight_smile: