Trouble-shooting Smart Rule for custom data element

I record my daily bodyweight in a custom data field in a DEVONthink document.

I have an iOS Shortcut that asks me for that weight, and then creates a note in DTTG with the name “Bodyweight xxx.x”

I want a Smart Rule in DEVONthink that takes that incoming document (after synchronization on my MacBook Pro ), and uses regex to extract that bodyweight number to enter into the custom data field.

My regex works, judging from the correct entry in the “Display Alert” dialog box.

But–nothing gets entered into the custom data field.

I can’t figure out what I’m missing.

thanks for any help or guidance!

Works fine for me if the custom metadata field is text or rich text

Does not work for me if the custom metadata field is a numerical field

I am curious - how do you process the set of data later on?

I presume you have or plan some sort of script or app which retrieves the custom metadata and graphs it or puts it in table form?

I actually hadn’t gotten there yet … but was hoping to be able to use the (numeric) custom data field to manipulate the data into a table.

I enter my weight once in a shortcut and from there it gets entered into the Apple Health app and it makes a text block I can paste into a markdown journal.
The journal tracks all sorts of things and I can flip back and see what I was watching, attending, reading, listening to, my weight, and some other personal metadata on top of my daily thoughts for any given day.

The Health app can show me trends and patterns if I want to look it at, which I do on occasion. I don’t obsess about the actual numbers just the variations and how that tracks with my mood and over all mental health (and added recently, blood pressure, ‘cause time don’t stop for no one, no how).

Consider using a smart rule script, just to make sure that types are correctly converted

function performsmartrule(records) {
	const app = Application("DEVONthink 3");
	app.includeStandardAdditions = true;
	
	const mdKey = 'bodyweight' // Use the key of your custom metadata field
	const re = /weight:?\s+([\d.]+)/;
	
	records.forEach (r => {
		try {
			const name = r.name();
			const weight = Number(name.match(re)[1]);
			app.addCustomMetaData(weight, {for: mdKey, to: r});
		} catch (error) { }
	})
}
1 Like

I guess you’re missing nothing. But the content of \1 is a string, and your bodyweight custom metadata field is a number. My hunch is that your rule works if you use a metadata field that’s defined as a string.

Or follow @meowky and use a script to set the metadata field.

Or improve on that script and add the data directly to a sheet in DT – seems the reasonable approach if you want to document the development.