Thank you so much for the help. The idea of HTML prompts is interesting, but I think I will need to wait for that. I’ve already probably used too much time on this. I was able to make this concept work. I figured I would share the full working code for my action in case it helps anybody. I will say that I have no real skill with JavaScript and just bang my head against my keyboard trying variations until something works. That being said, this is probably not the most beautiful code ever.
First, a little background: I’m working on my Ph.D. currently. With buying a new M1 MacbookAir, I’ve been more heavily relying on MacOS. I had a shortcut that created this same file in drafts for me. It also uses DataJar to pull the Arrays that I use, and I don’t like having to “hard code” them into my script, but until I make a plan for what to do about not currently having access to DataJar on MacOS, this might be what I do.
The way I do my academic writing is that the first line of a draft is the document’s title. The second line of the draft is the folder where I will save it. I have an action that will convert my markdown to HTML, and I can post discussion replies to our Canvas. After completing and publishing my discussion, I can later process it and decide if I need to do anything else with the text or save a version in my OneDrive account.
The code creates a prompt that has some pickers and a text field for my classes. It sets up the file name/folder variables, along with some data that I want to save as YAML metadata. I had to use if(){}
, if else(){}
statements to determine the array number of the selected response and provide text for the addPicker()
. It also splits one of the variables so that my metadata can have separate data about the Course ID and Course Title.
It creates a new draft with a template pulling the variables gathered from the prompt. The draft processes itself again to use other templates (e.g., the date). It also adds tags. I separate my tags by category (i.e., "l - " is a location or area of my life, "a - " is an action, and "s - " is a status).
Anyways, I hope that my banging my head against my keyboard is useful for others.
// Template Set Up for new writing projects for classes
// Create Prompt
var p = Prompt.create();
p.title = "CIIS New Writing Project";
p.message = "Fill in form to create new CIIS writing project.";
p.addPicker("pickerCourseDescription", "Course: ", [["Reverse Imagineering", "Methodology Comprehensive Examination", "Literature Review Comprehensive Exam", "Learning Community IV"]], [0]);
p.addPicker("pickerLocation", "Location: ", [["Personal Journal Space", "Research Journal", "Small Group Discussion", "Large Group Discussion", "Paper", "Document"]], [3])
p.addTextField("textFieldTopic", "Topic: ", "");
isCancellable: true;
p.addButton("Ok");
if (p.show())
// Set up frontmatter and project variables
var topic = p.fieldValues["textFieldTopic"];
// Course variable
var courseIDandTitle;
if (p.fieldValues["pickerCourseDescription"] == "0") {
courseIDandTitle = "TSD 6137 - Reverse Imagineering";
} else if (p.fieldValues["pickerCourseDescription"] == "1") {
courseIDandTitle = "TSD 9611 - Methodology Comprehensive Examination";
} else if (p.fieldValues["pickerCourseDescription"] == "2") {
courseIDandTitle = "TSD 9610 - Literature Review Comprehensive Exam";
} else if (p.fieldValues["pickerCourseDescription"] == "3") {
courseIDandTitle = "TSD 8420 - Learning Community IV";
} else {
courseIDandTitle = "There is an error in pickerCourseDescription";
}
// Split Course ID and Title Variable
var res = courseIDandTitle.split(" - ");
var courseID = res[0];
var courseTitle = res[1];
// Location variable
var location;
if (p.fieldValues["pickerLocation"] == "0") {
location = "Personal Journal Space";
} else if (p.fieldValues["pickerLocation"] == "1") {
location = "Research Journal";
} else if (p.fieldValues["pickerLocation"] == "2") {
location = "Small Group Discussion";
} else if (p.fieldValues["pickerLocation"] == "3") {
location = "Large Group Discussion";
} else if (p.fieldValues["pickerLocation"] == "4") {
location = "Paper";
} else if (p.fieldValues["pickerLocation"] == "5") {
location = "Document";
} else {
location = "There is an error in pickerLocation";
}
{
// create the draft
let d = Draft.create();
d.content = `[[date]], ${location} Topic - ${topic}
${courseIDandTitle}
---
Course ID: ${courseID}
Course Title: ${courseTitle}
Date: [[date]]
Location: ${location}
Topic: ${topic}
---
# ${location} Topic
**Topic**: ${topic}
**Date**: [[date|%m/%d/%Y]]
**Title**:
---
`;
wholeContent = d.content;
d.content = d.processTemplate(wholeContent);
d.addTag("l - ciis");
d.addTag("a - process");
d.addTag("s - draft");
d.update()
// load in editor and focus for editing
editor.load(d);
editor.activate()
}