Set Custom Metadata to Scan Text Amount?

Have defined a Custom Metadata field as follows:

Amount
Decimal Number, Currency

Smart rule actions

Scan Text | Amount | *

Change Amount | to | ___ ?

The input box for Change Amount (___) does not allow the use of an Insert Placeholder which I would set to Document Amount.

I can however do this:

Change Company | to | $1234.56 (Document Amount)

How does one set a decimal number Custom Metadata field to the amount parsed/matched with Scan Text Amount?

Came up with this rather inelegant solution of adding this script after the rules above:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set customMD to custom meta data of theRecord
			add custom meta data mdcompany of customMD as number for "Amount" to theRecord
			add custom meta data "" for "Company" to theRecord
		end repeat
	end tell
end performSmartRule

Am having trouble believing there’s not a cleaner path.

An attribute with a numerical value is expecting a number not a string, so placeholders aren’t supported. If you changed the data type to Single-line Text you could use a placeholder.

Odd limitation; makes one wonder why there is even a Scan Text | Amount selection present.

Scan Text | Date functionality is able to parse and assign a date to attributes with a date type. Am assuming of course that dates are not being stored as strings behind the scenes.

So to clarify, in a smart rule, if one has a Custom Metadata field that is numeric, there is no way (outside scripting) to assign a value other than to provide a static fixed numeric value for any numeric attributes?

Each to define which of multiple amounts in a document should be used by the Document Amount placeholder. A future release will probably extend the possibilities.

I’d like to add my vote for allowing this to happen.
Scan Text (Amount) to a Custom Metadata field that is set as numerical.

Thanks

I’d like to use this solution but I can’t get it to work on my end. I’m trying to get my data into a custom metadata field called “amount” using a custom metadata field called notesrec.

I thought by adding your script to a smart rule that does the same thing as your 3 steps, then switching out your Company with my “notesrec” and your Amount with my “amount”, that it should work.
Could you maybe clue me in with what’s happening in that script? Thanks in advance.

Again: Show the code. Otherwise, people don’t know that you really did.

The smart rule:

The Script:

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set customMD to custom meta data of theRecord
			add custom meta data mdcompany of customMD as number for "amount" to theRecord
			add custom meta data "" for "notesrec" to theRecord
		end repeat
	end tell
end performSmartRule

Thanks for any attention to this.

I seem to remember that „Scan“ uses regular expressions. In that case, $ would represent the end of the string. You could try to escape it like so \$

The first two parts of the rule work. They get the value string from the document and copy it to the Notes because Notes is alphanumeric. Trying to get that string from Notes into Amount is where I get lost. I was trying to figure out @recipedude ‘s script but got a little lost as to what is doing what in there. I changed his variables to mine but don’t know what else to do.

In my words: You extract an amount from a PDF document using a smart rule action. Then you assign this string to a custom meta data field named “Notes(REC)”. Then you run the script that

  • saves the current custom meta data of the record to customMD (why)?
  • converts the mdCompany field of customMD to a number (why?)
  • takes this “value” to set the custom meta data field amount
  • finally clears the custom meta data field notesrec

First, in order to debug this, you should trim down the script to the absolute necessary and run it in Script Editor (or Script Debugger, which has a free edition) when a sample record is selected. So something like

tell application id "DNtp"
  repeat with theRecord in selected records
    set customMD to custom meta data of theRecord
    add custom meta data mdcompany of customMD as number for "amount" to theRecord
    add custom meta data "" for "notesrec" to theRecord
 end repeat
end tell

Then you can see which Apple Events are sent and what the answers look like. Which helps to understand what’s going wrong. And is one step in systematically finding and solving problems.

Which here gives me:

Interestingly … because I set (manually) the “Company” field of this record to the amount. However, you don’t do such a thing: You set the field Notes(REC) (note the parenthesis) in your smart rule. But in your script, you retrieve the value of mdcompany (i.e. the pre-defined meta data field “Company”), convert that to a number (which might give 0 or some other useless value) and then add this value to your custom meta data field “amount”. Which then is probably 0 or empty or some other useless value.

Finally, you set the custom meta data field “notesrec” to the empty string – although in your rule, you used “Notes(REC)”, which has quite a different spelling.

To summarize: In your rule, store the amount in a custom meta data field (e.g. notesrec). Use the very same field (e.g. notesrec) in your script like so
set myAmount to get custom metadata for "notesrec" from theRecord
(yes, there’s even a method for that, no need to get the custom meta data record first and then index into it). And then use this to set your amount field like so
add custom meta data myAmount as number for "amount" to theRecord
and finally clear the notesrec field like you did before

Disclaimer: I do not think that this is a very good method to achieve what you want. It works, but it mostly works around limitations of the smart rule system. Instead, I’d write a script that does everything: Extract the amount and set the custom meta data (in fact, I did that for my purposes). That also avoids introducing a completely useless custom meta data field. However, the document amount field seems to be utterly useless for this purpose (at least in the one case where I test it). So your script would have to find the amount it is interested in by itself.

I add my upvote to this as well. A custom numerical field should accept the appropriate numerical placeholder, just as a custom date field accepts an appropriate date placeholder.

I am reading your (@chrillek) efforts here which seems to be the way to go. I am going to dig into that script and see if it can make my life a little easier.
When I get some time I will go through your notes above about this script and try to learn from it as well.
Thanks