Action

Open List

Posted by agiletortoise, Last update 12 months ago

This is a companion action to the “Add to List” example. This action can be used to quickly open one of your existing list drafts to review.

Learn more in the related forum tip article

Steps

  • script

    // Configurable options
    
    // set to name of tag to use to identify list drafts
    const tag = "list"
    
    
  • script

    // will be used to hold the target list draft
    let listDraft
    
    // finds existing "list" drafts
    function getListDrafts() {
    	let drafts = Draft.query("", "all", [tag])
    	return drafts
    }
    
    // prompt for options
    let f = () => {
    	let listDrafts = getListDrafts()
    	let p = new Prompt()
    	p.title = "Select List to Open"
    	p.isCancellable = true
    	if (listDrafts.length > 0) {
    		for (let d of listDrafts) {
    			p.addButton(d.displayTitle, d)
    		}
    	}
    	else {
    		alert(`No lists found. Tag at least one draft with the tag “${tag}” to use this action.`)
    		return false
    	}
    	if (p.show()) {
    		listDraft = p.buttonPressed
    		return true
    	}
    	else { // user cancelled
    		return false
    	}
    }
    
    if (!f()) {
    	context.cancel()
    }
  • script

    editor.load(listDraft)
    

Options

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