Smart Rule is not processed on importing

Hi,

I have a smart rule which checks for a custom meta field (Status), which is set when importing a document in another rule before:

Any ideas, why the rule is not executed after importing a document? Aren’t the rules running one after the other when importing a document?

Please provide more information, e.g., what both rules are doing.

Thank you for your prompt reply.

In the I scan for a date within the document and set a custom meta date field. (This still cannot be done, without using a script, correct?). Then I change a custom meta field to the value “ready to be renamed”:

In the following rule I check, if the custom meta field is set to “ready to be renamed” and change the file name using the date which is set in the the custom meta date field which was set in the rule before:

How do you determine the sequence in which the smart rules are executed? And how do you determine that the second rule is not executed? Do you see any messages in the protocol?

Perhaps it might be easier to use just one rule with one JavaScript script, thus avoiding the awkward fiddling with “Status”.

Aside: You might want to check the spelling you use in the “Titel” field in the first rule … (Just wondering why you replicate a tag in a custom metadata field).

And which rule is the first one in the sidebar? The order is important.

Only if the custom metadata was text-based, e.g., Single-Line Text, not a Date data type.

Only custom metadata that can be changed are listed as Change … in the smart rule actions. Ones with a Date data type aren’t listed.

How do you determine the sequence in which the smart rules are executed?

I assumed that the rules run in the same order as they are laid out in devonthink (from top to bottom).

And how do you determine that the second rule is not executed? Do you see any messages in the protocol?

The second rule is a least not executed after the first rule, because the “Status” field is still set to to “ready to be renamed” and not “renamed”.

Perhaps it might be easier to use just one rule with one JavaScript script, thus avoiding the awkward fiddling with “Status”.

This would work, but I the second rule is kind of generic and is run after several other rules and I would like to dermine the order of the rules within the UI of devonthink an not in the javascript.

Aside: You might want to check the spelling you use in the “Titel” field in the first rule … (Just wondering why you replicate a tag in a custom metadata field).

Which “tag” is replicated?

I assumed that the rules run in the same order as they are laid out in devonthink (from top to bottom. The first rule is above the second rule.

The second rule is set to On Import but there’s no import happening. There is no event trigger for when metadata changes on a document. You could use an intervallic trigger, e.g., Every Minute.

It’s possible you could use the Apply Rule action and run the second rule explicitly, but this would also depend on the specific rule. However, you did say it’s generic so maybe it would work here.

And Step 2 is just applying a color label with an On Demand event trigger.

Both rules are triggered On Import. The first rule is executed on import and sets the metadata. Shouldn’t the second rule be then excuted on the imported document after the first rule is finished?

Actually, yes they will.

Here are two rules that work On Import

The sounds played depend on the order of the rule in the Smart Rules list. But the matching criteria are simple and satisfied by the imported document.

However, the Status of the document in your scenario is not set on import. It’s set by the previous smart rule.

If you had a smart rule that tagged a file on import, a subsequent smart rule would not execute with an On Tagging event trigger, even if the criteria matches the tagged file. A smart rule doesn’t initiate event triggers in other smart rules.

In this instance, you could use On Tagging to do some action when you manually tag an item but call it from another smart rule. This would correctly be called chaining smart rules.

… runs…

But, logically, Step 2 would only run if it also had matching items to work with.
And Step 2 could run as a standalone smart rule, as needed.

Rechnung
And that the status is not set might be caused by an error in the script. That’s why I asked for log messages.

The easiest approach might be to append the Apply Rule action to the first rule to explicitly execute the second rule.

I see. But status is set correctly in the first rule.

Many thanks for the clarification.

1 Like

I have managed to run the rule On Import by moving the evaluation of the custom metadata Status from the rule into the JavaScript:

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  app.includeStandardAdditions = true;

  /* Loop over the records selected by the smart rule */
  records.forEach(r => {
    if (app.getCustomMetaData({ for: "status1", from: r }) == "ready to be renamed") {
      app.logMessage("rename document");
      renameDocument(r)
      app.addCustomMetaData("renamed", { for: "status1", from: r })
    }
  })
}

Thank you for your help.

If it were me, I’d try to figure out if the file needs to be renamed by looking at the name instead of fiddling around with a meaningless status. What’s the point of having a bunch of renamed files sitting around with a status saying “renamed”? Or perhaps set the status to “”?

Thank you. I see your point.
renamed is only one of several statuses, that a document can have during my workflow. The final status is processed.