Action

Created This Day

Posted by agiletortoise, Last update about 4 years ago

Loads drafts created on the current date in previous years.

The action will prompt for the number of years ago to view, then create an open a workspace to display only drafts created on today’s date that number of years ago.

This is meant as an example of date filters in Workkspaces.

Steps

  • script

    function load(numberOfYears) {
    	// get date for previous year
    	let d = Date.today().add(-numberOfYears).years();
    	
    	// create a workspace with a date filter for that day
    	let ws = new Workspace();
    	ws.name = "Created: " + strftime(d, "%Y-%m-%d");
    	
    	let st = new QueryDate();
    	st.field = "created";
    	st.type = "absolute";
    	st.date = d;
    	
    	let end = new QueryDate();
    	end.field = "created";
    	end.type = "absolute"
    	end.date = d;
    
    	ws.startDate = st;
    	ws.endDate = end;
    	
    	app.applyWorkspace(ws);
    }
    
    if (app.isPro) {
    	let p = new Prompt();
    	p.title = "On This Day";
    	p.message = "Display drafts created on this date in a previous year. Select the 	number of years ago below."
    	
    	p.addSelect("years", "Years ago", ["1", "2", "3", "4", "5"], ["1"], false);
    	p.addButton("Show", "Show", true);
    	
    	if (p.show()) {
    		let years = parseInt(p.fieldValues["years"]);
    		load(years);
    	}
    	else {
    		context.cancel();
    	}
    }
    else {
    	alert("This action uses Workspaces, which require a Pro subscription");
    	context.cancel();
    }
    
    

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.