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:

@cgrunenberg just checking, should this work right now (3.8.3)? I can’t get it to work in my test.

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			perform smart rule name "Resources: save content" record theRecord
		end repeat
	end tell
end performSmartRule

A screenshot of the smart rule would be useful.

It’s a pretty complex rule that might be irrelevant to this question so I’ve craeted a small test setup with two rules “Test 1” and “Test 2”:

Test 1

Test 2
2022-05-20 CleanShot CleanShot 10.21.45

When running Test 1 as a Smart Rule (Apply Rule - it currently matches 2 documents starting with “1984”) it does nothing. Running the same code (using selection as list) for theRecords) from Script Debugger / Editor it works as expected and shows the alert.

The next release will be actually 3.8.4 and it’s working fine over here in the latest internal builds.

1 Like