Action

Flexible Packing List

Posted by @nahumck, Last update over 2 years ago - Unlisted

UPDATES

over 2 years ago

Changed the action name from “variable” to “flexible”.

show all updates...

over 2 years ago

Changed the action name from “variable” to “flexible”.

over 2 years ago

One last fix to add some text for export.

over 2 years ago

Refactored the collection of Drafts content. (Thanks Greg for the assist!)

over 2 years ago

Fixed a syntax errors for the trip name and added the trip name to the subsequent checklist prompt step.

Create a flexible packing list by selecting one or more categories (queries drafts with the packing tag). Processes the selected categories into a single packing list and creates a new draft. Optionally send to Reminders as a task.

Steps

  • script

    /*--- Create Trip Name Prompt ---*/
    
    // Trip Name Prompt
    var p = Prompt.create()
      p.title = "Enter List Name"
      p.addTextField("tripName", "Trip Name", "", {"placeholder":"Enter List Name","autocapitalization":"words","wantsFocus":true})
      p.addButton("OK")
      p.show()
    
    // Create variable for later use
    var tripTitle = p.fieldValues["tripName"]
  • script

    /*--- Create Checklist Prompt ---*/
    
    // Query all drafts with tag `packing` to get category titles
    // get your category drafts
    let catTitles = []
    let drafts = Draft.query("","archive", ["packing"])
    // map them to a lookup object
    let lookup = {}
    for (let t of drafts) {
    let dTitle = t.displayTitle
    catTitles.push(dTitle)
    lookup[dTitle] = t
    }
    
    // Checlist Prompt
    var p = Prompt.create()
    p.title = "Select Categories for "+tripTitle
    p.message = "Select one or more categories to add to your list."
    // change [] to catTitles
    p.addSelect("categories","Categories",catTitles,[],true)
    p.addButton("Create Packing List")
    
    var success = p.show()
    var selected = p.fieldValues["categories"]
  • script

    /*--- Compile ---*/
    
    // Combine selected drafts together into a single draft
    
    if (success) {
    	let packingList = "# "+tripTitle+"Packing List \n"
    	for (let sel of selected) {
    	// Pull draft from lookup table
    	let found = lookup[sel];
    	// Pull content from draft 
    	var content = found.content
    	// Combine selected draft content
    	packingList = packingList+"\n"+content
    	}
    
    	let d = new Draft()
    	d.content = packingList
    	d.update()
    	var url = d.permalink
    
    }
    else {
    	context.cancel()
    }
  • script (disabled)

    //Create Task in Reminders
    
    var list = ReminderList.findOrCreate("Inbox")
    var reminder = list.createReminder();
    reminder.title = tripTitle;
    reminder.url = url;
    reminder.notes = url;
    reminder.update();

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.