Append to Craft Note with a current date

Hello, I’m a bloody beginner in scripting.
I want to adapt the Append to Craft Note Action by @FlohGro (thank you for sharing) to insert the current date before appending the text.
I’ve tried it with a “let” declaration and inserted "cb.addParameter(“today”,today).
Here’s the script:

const spaceID = “6743b144-fb98-6a79-f6f0-be8a128673ee”
const parentBlockID = “76A760B2-2933-4D0C-879E-EC70C5CEC0F5”
if(spaceID == “unconfigured” || parentBlockID == “unconfigured”){
let errorMsg = “the spaceID & / or the parentBlockID variable was not configured in the script”
alert(errorMsg)
context.fail(errorMsg)
} else {
let content = draft.processTemplate("[[draft]]")
let today = new Date()
const baseURL = “craftdocs://createblock?”
// index needed as high number to append the content at the end of a craft document
const index = 100000
var cb = CallbackURL.create()
cb.baseURL = baseURL
cb.addParameter(“spaceId”,spaceID)
cb.addParameter(“parentBlockId”,parentBlockID)
cb.addParameter(“index”,index)
cb.addParameter(“today”,today)
cb.addParameter(“content”,content)
//cb.addParameter(“folderId”,"")
cb.waitForResponse = false
//let result = cb.open
cb.open()
}

Good news: No error message.
Bad news: Nothing will be inserted (the script is running like before).

Thanks for any help.

great that this action is useful for you:

your action doesn’t work, since the cb.addParameter() adds a parameter to the callback url. if the called app doesn’t support this parameter this will either be ignored or the complete url action won’t be executed.

I created two new actions for Append and Prepend with a date prefixed to the content, you can download them in the action directory :

note: i assumed the date format and used the ISO format (YYYY-MM-DD) but you can change that format in the script as also mentioned in the action description.

1 Like

Thank you very much. That’s awesome :smiley:

1 Like