Action

Today's Drafts to New Draft

Posted by sylumer, Last update about 3 years ago - Unlisted

Steps

  • script

    function mergeDraftsToday(p_Separator = "\n")
    {
    	// Create a new workspace object
    	// We are not going to save this, just use it to get today's drafts
    	let wsToday = Workspace.create();
    
    	// Build a query date for drafts created today
    	let qdStart = new QueryDate();
    	qdStart.field = "created";
    	qdStart.type = "absolute";
    	qdStart.date = Date.today();
    
    	// Assign the query date to the workspace
    	wsToday.startDate = qdStart;
    
    	// Get an array of drafts from the inbox for the 'today' workspace
    	let adToday = wsToday.query("inbox");
    
    	// Create an empty array and populate it with the content of today's drafts
    	// Each draft's content becomes a separate element in the array
    	let astrOutput = [];
    	adToday.map(dToday => astrOutput.push(dToday.content))
    
    	// Create a new draft from the array of draft content
    	// The drafts are concatenatd using a separator string passed into the function
    	let dNew = Draft.create();
    	dNew.content = astrOutput.join(p_Separator);
    	dNew.update();
    
    	// Load the new draft and activate the editor
    	editor.load(dNew);
    	editor.activate();
    }
    
    // Merge today's drafts into a new draft with two newline characters between each of the drafts' content
    mergeDraftsToday("\n\n");

Options

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