Smart Rule: Moving a comment text to a custom meta field

Hi,
I want to set a custom meta field from the text in a finder comment using a smart rule. It kind of works with this AppleScript in the rule

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set theComment to the comment of theRecord
			add custom meta data theComment for "betrag" to theRecord
		end repeat
	end tell
end performSmartRule

“betrag” is the name of the custom meta field and it get’s set ok with this script. However, I also get a new custom meta field with the name of theComment’s value and it’s value also the value of theComment.
E.g. if the finder comment is 60, after the rule is executed, I have 60 in betrag, but I also have a custom meta field “60” with a value of “60”.
Is this a bug in my script or in DT3?
If, on the other hand, I do not use add custom meta data
but

set mData to the custom meta data of theRecord
set betrag of mData to theComment

I get the error message that mData is not defined.
Is this due to the fact that the custom meta data field is empty?

Interesting. I fiddled around with this problem in the script editor where my first script worked ok. Now it’s working in DT3, too.

And what code did you end up with?

That’s what I copied from my rule (to make sure I don’t introduce typos)

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			set theComment to the comment of theRecord
			add custom meta data theComment for "betrag" to theRecord
		end repeat
	end tell
end performSmartRule

looks very much lik the first script I posted, but this time it’s working.
Was my assumption correct that
set mData to the custom meta data of theRecord
returns an empty mData if the the custom meta data field(s) do not contain values?

Yes, that’s why you got the error.

And your working script is the easiest way to handle modifying custom metadata.

This should also be possible without using AppleScript, just add the Change Betrag action and insert the placeholder for the Finder Comment in the text field.

Thanks again, that sounds a lot easier. However, what is the “placeholder for the Finder Command”? If I select “Betrag ändern” in the rule’s action drop down, I only get a text field. What would I type in it?

I assumed that “Betrag” is defined as text (and that the Finder comment could contain any text), in case of numbers this is indeed not possible.