Action

Microsoft To Do: Import List

Posted by agiletortoise, Last update over 3 years ago

UPDATES

over 3 years ago

Fixed undefined title issue.

Example code for working with Microsoft To Do via script. See scripting reference for details on available methods.

This action prompts user to select one of their MS To Do lists, then imports the tasks from that list and builds a new draft with a Markdown list representation of the tasks.

Steps

  • script

    // Demo script
    // Prompts user to select from the Microsoft To Do lists
    // And builds new Markdown list from the active tasks
    
    let f = () => {
    	// create MicrosoftToDo object
    	let todo = MicrosoftToDo.create();
    	// get all lists from account
    	let lists = todo.getLists();
    	if (!lists || lists.length == 0) {
    		alert("No lists to import");
    		return false;
    	}
    
    	// prompt to select a list
    	let p = Prompt.create();
    	p.title = "Select List to Import";
    	for(let list of lists) {
    		p.addButton(list.displayName, list);
    	}	
    	if (!p.show()) { return false; }
    
    	// get tasks from the selected list
    	let selectedList = p.buttonPressed;
    	let tasks = todo.getTasks(selectedList);
    	if (!tasks || tasks.length == 0) {
    		alert(`No tasks found in list "${selectedList.displayName}"`)
    		return false;
    	}
    
    	// build an array of strings with task values
    	let result = [];
    	result.push(`# ${selectedList.displayName}
    
    `);
    
    	// loop over tasks and build list
    	for (let task of tasks) {
    		if (task.status == 'completed') {
    			result.push(`- [x] `);
    		}
    		else {
    			result.push(`- [ ] `);
    		}
    		result.push(`${task.title}
    `);
    	}
    
    	// put the results in new draft and load it
    	let d = new Draft();
    	d.content = result.join('');
    	d.update();
    	editor.load(d);
    	return true;
    }
    
    if(!f()) {
    	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.