Action

Create Craft Note

Posted by FlohGro, Last update almost 3 years ago

UPDATES

almost 3 years ago

typo fixed

show all updates...

almost 3 years ago

typo fixed

almost 3 years ago

added note on how to retrieve the space id

almost 3 years ago

fixed typo

almost 3 years ago

updated to use credentials of craft space instead of manual need to configure the space id in the script step. description updated

over 3 years ago

description update

over 3 years ago

updated to use x-callback-url and fixed create document issues by encoding the content

over 3 years ago

updated to use x-callback-url scheme.

created by @FlohGro / more on my Blog

Create Craft Note

This action creates a new Document in Craft in a configurable space.

[Configuration]

If you don’t want to use the (any of my) action for different Craft spaces there is no configuration needed. When you first run any of my Craft actions it will ask you to store the space id of your Craft space. This is a one time action and you don’t need to do it for any other of my Craft actions you install.

To retrieve your spaceId just copy the deeplink of any document in that space (refer to the Craft Support Page when you don’t know how to do that). Paste the copied id into a draft and you will se a link similar to this: “craftdocs://open?blockId=[the block id]&spaceId=[the spaceId]” - find the character combination “[the spaceId]” after the “spaceId=” and copy it and paste it into the prompt of this action.

To use these actions with different spaces you need to duplicate the action for each space you want to use it. I recommend to e.g. add a suffix to the action name to describe the space for which you configure it.

The action uses Drafts possibility to store credentials to distinguish different spaces. When you duplicate the action for another space you have to change the name of the credential. Therefore you need edit this line const spaceIdCredentialName = "CraftDocumentSpace" in the script step of the action and change the CraftDocumentSpace to something different (e.g. describe the space in a suffix like „CraftDocumentSpacePersonal" or „CraftDocumentSpaceWork“. If you use several of my Craft actions you should use the same credential name in all of them.

[Usage]

When you made notes during a meeting or while reading something and you decide to move the notes to Craft, simply run this action and it will create and open the new document in Craft. The markdown formatting will not be changed and applied to each created block in Craft.

If you want to use the actions for different spaces in Craft just follow the instructions above.


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    // created by @FlohGro
    
    // optional configuration of the spaceIdCredentialName - only necessary if you want to use the same action for different Craft Spaces
    const spaceIdCredentialName = "CraftDocumentSpace"
    
    
    let spaceID = getCraftSpaceIdToUse();
    
    let title = draft.displayTitle
    
    let content = draft.processTemplate("[[body]]")
    
    content = encodeURIComponent(content)
    
    const baseURL = "craftdocs://x-callback-url/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 = true
    
    let result = cb.open()
    
    if (result == true) {
        console.log("Craft note successfully created")
    } else {
        console.log("Craft note result:" + cb.status + " " + cb.callbackResponse)
        if (cb.status == "cancelled") {
            context.cancel()
        } else {
            context.fail()
        }
    }
    
    function getCraftSpaceIdToUse() {
        let credential = Credential.create(spaceIdCredentialName, "Credential to store the spaceId of the space you want to use in Drafts.\ninsert your spaceId into the TextField below. \n\nNOTES: \n- this is a one time action, you don't need to do it everytime\n- Multiple spaces are currently not supported with this spaceId credential helper");
        credential.addTextField("spaceId", "spaceId");
        if (credential.authorize()) {
            return credential.getValue("spaceId");
        } else {
            let errorStr = "failed storing / retrieving space Id with credential"
            app.displayErrorMessage(errorStr);
            context.fail(errorStr);
            console.log(errorStr);
            return false;
        }
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.