Error when creating note in Craft

Newbie here, thanks in advance for any help. @FlohGro posted an action Create Craft Note and I’m unable to get it to work. It needs configuration before first use:

You can get it by copying the deepplink of a document in this space. Paste the link into a new draft and extract the combination like “2159f404-e3ed-4d8a-fbe1-6c361399c8f3” after spaceId= in the link. replace “unconfigured” with this id in the spaceID variable of the script.

I obtain the deep link in Craft, extract the SpaceID, and replace “unconfigured” in 2 places in the action (line 7 and line 9). I’m unsure of whether to leave the quotes around the variable so I’ve tried it both ways. With quotes I get an error of “the SpaceID variable was not configured in the script” and without quotes I get an error of “Syntax error: no identifiers allowed directly after numerical literal”.

Here is the @FlohGro script for reference:

> // created by @FlohGro
> 
> // create Craft note
> 
> // insert your preferred space ID for a document here. You can get it by copying the deepplink of a document in this space. Paste the link into a new draft and extract the combination like "2159f404-e3ed-4d8a-fbe1-6c361399c8f3" after spaceId= in the link. replace "unconfigured" with this id in the spaceID variable.
> 
> const spaceID = "unconfigured"
> 
> if(spaceID == "unconfigured"){
> 
> let errorMsg = "the spaceID variable was not configured in the script"
> alert(errorMsg)
> context.fail(errorMsg)
> 
> } else {
> let title = draft.displayTitle
> 
> let content = draft.processTemplate("[[body]]")
> 
> const baseURL = "craftdocs://createdocument?"
> 
> var cb = CallbackURL.create()
> cb.baseURL = baseURL
> cb.addParameter("spaceId",spaceID)
> cb.addParameter("title",title)
> cb.addParameter("content",content)
> cb.addParameter("folderId","")
> cb.waitForResponse = false
> cb.open()
> 
> }

Thanks for using the action, you only should replace the „unconfigured“ in line 7 (the declaration of the variable)
The quotes are needed to declare this variable as string.

Hope that helps

2 Likes

So simple. Thanks @FlohGro , that fixed it. Thanks for contributing the action too!

2 Likes