Using new DT4 Query Response placeholder in Smart Rules

I’m trying to create a smart rule that executes a AI chat for each document and places the results in a custom metadata field.

However, I can’t seem to reference the Query Response placeholder in the Smart rule.

Should I be able to use %queryResponse%, or %query response% in the “Change < metadata field>” action?

Placeholders can be inserted via the Insert Placeholder submenu of the contextual menu of text fields in the smart rule & batch processing editors. Or via the new pop-up button at the right edge of these fields:

Okay, thank you - that works. I was trying to type the placeholder - which appears to be possible in some cases but not this case. The documentation seems to imply the name is “Query Response”, and the pop-up says that too - but it appears to be %chatSuggestedResponse% behind the scenes.

The responses fill the metadata field so I’m trying to change the approach to create a new item in the database (with the response and a link to the original item) but it appears I’ll have to shift to an AppleScript approach for that.

You could also use annotations instead of custom metadata, e.g. like this:

2 Likes

Thank you - that example has actually helped a lot. Those script related actions didn’t make sense to me before - but I’m able to do exactly what I want now. Thanks again.

You’re welcome!

1 Like

Are the any plans or possibly even already possibilities to expand the use of AI generated placeholders to other kind of fields (like a date field)?
For me, it feels counter-intuitive to use a textfield to hold a date-information.

1 Like

For me, it feels counter-intuitive to use a textfield to hold a date-information.

Dates as strings offer more flexibility in formatting the date, e.g., DD-MM-YY.

I feared that you started to become reasonable again :grin:
Well - for me this means that I would need to rebuild my data for those documents that currently have a date field - but that is my issue.

Maybe the document date placeholders are already sufficient? E.g. since version 4 it’s possible to set dates, e.g. creation or modification date, to the (newest/oldest) document date via smart rules and batch processing.

@cgrunenberg Thank you for pointing this out.
Seems that I need to play a little more with v4 to get used to all changes.

In the last days, I testes the built-in possibilities to manipulate date fields, as @cgrunenberg suggested.
Unfortunately, in a document with several dates (like in my case - validity date of the contract, print date of the document and the desired “real” date, when the document was issued).
So I ended up using AI to create a document title in the form of

document date (YYYY-MM-DD) document title (e.g. 2015-05-04 1&1 Telecommunication invoice)

And afterwards, I use an Apple Script to copy the found date into the creation date field.
I have enclosed the script in question, just in case someone is having comparable issues.

tell application id "DNtp"
	
	repeat with thisRecord in (selection as list)
		
		set today to (current date)
		set recordName to (name of thisRecord)

        -- use the first 10 characters as date string and extract the numbers for year, month and day
		set titleDatestring to characters 1 thru 10 of recordName as string
		set myYear to characters 1 thru 4 of titleDatestring as string
		set myMonth to characters 6 thru 7 of titleDatestring as string
		set myDay to characters 9 thru 10 of titleDatestring as string
		
		-- create the date from the extracted information
		set day of today to myDay as integer
		set month of today to myMonth as integer
		set year of today to myYear as integer
		
		-- create a new variable creation to to manipulate further
		copy today to creationDate
		
		-- Set the time to midnight (as I do not need it)
		set time of creationDate to 0
		
		-- Copy 'creationDate' into 'creation date' in the record's metadata
		set creation date of thisRecord to creationDate
		
	end repeat
	
end tell

An example title with a date would be helpful.

Ideally as rich text should be as string. It doesn’t seem to cause troubles in this case but in other cases it might.

Added as per your suggestion, thank you!

You are right, I will amend the script accordingly.
Thank you for pointing this out.

1 Like

You’re welcome.

1 Like

Was that a script you wrote or AI-generated?

I would say so and so.
The basic structure was created by Google Gemini and since that wasn’t working, I was able to find the issues and correct them (this was mainly the way Gemini tried to create the date to be written into the created date field).

As has been mentioned quite a few times, AI-generated scripts are pretty poor. In fact, I could ask more questions about “Why did you do ______ ?”, hence my inquiry about AI.

I would recommend you learn some scripting on your own, especially as the script you presented does a very low-level operation that can easily accomplished. Also note the AI provides no insight into what it’s doing and why.

Here is a learning edition script that does the same function…

tell application id "DNtp"
	if (selected records) is {} then return -- If nothing is selected, just stop.
	
	set od to AppleScript's text item delimiters -- Cache the default delimiters
	
	repeat with thisRecord in (selected records)
		set recordName to (name without extension of thisRecord) -- "2015-05-04 1&1 Telecommunication invoice"
		
		set AppleScript's text item delimiters to " " -- Split the name on spaces
		set theDate to text item 1 of recordName -- Get the date, which is the first item before a space
		log theDate --> 2015-05-04
		
		set AppleScript's text item delimiters to "-" -- Split the date on hyphens
		set {myYear, myMonth, myDay} to {text item 1, text item 2, text item 3} of theDate -- Grab each date component
		
		set creation date of thisRecord to my getdate({myMonth, myDay, myYear} as string)
		-- The order of the date components are locale-aware. In the US, M-D-Y processes to a proper date
		
		set AppleScript's text item delimiters to od -- Set the delimiters back to default
	end repeat
end tell

on getdate(theDate)
	return date theDate -- The date coercion doesn't work inside a DEVONthink tell block
end getdate