What I’m trying to do
I’m trying to add a button to my note templates for daily, weekly, and customer notes which will create a file in a given directory with the appropriate template and feed it values so certain things in the file start out correctly populated. For context, the created file will be used while working on a customer case.
From my weekly and daily notes, I would like the button to prompt for the customer name, ID number, and description.
From the customer’s page, the template for the customer page should ask me for the customer name when I create that page, and set up the button so that it doesn’t ask for Customer Name when it is used from there.
When the Customer page is created, it should rename the page with a string composed of the customer name, ID, and description concatenated and cammelCased, and populate other fields through the new note.)
I’ve gone through tickets here and threads on Reddit but haven’t found an example that helped me, so if you know of one, please lmk. So far, everything I’ve worked through has just gotten me deeper down the hole, so now I’m running into concurrency errors.
Things I have tried
I’ve been playing with the Meta Bind and Buttons plugins but my templates fail.
I’m hesitant to share what I’ve done so far because I want to hear about other ideas, not poisoned by mine. Still, jic I’m on the right track, or someone knows what stupid simple thing I did wrong:
The route I’m going with atm is to have the button create the file and leave all the actual work to Templater. Here’s the block of Templater code that’s getting concurrency issues.
This does not work but my focus is just getting the data flowing correctly, then I can work on things like the camel case function etc.
Templater code
<%-*
let fileName = tp.file.title, description = "", titleArray = [], customer, ticketID;
// if (fileName.startsWith("Untitled") ) {
customer = await tp.system.prompt("Customer: ");
customerHyph = customer.replace(/ /g, "-");
customerNoSpace = customer.replace(/ /g, '');
ticketID = await tp.system.prompt("Ticket ID: ");
description = await tp.system.prompt("Issue Description: ");
descriptionNoSpace = description.replace(/ /g, '');\
await filename = "Case/" + tp.user.camelCase(customer) + "-" + ticketID + "-" + tp.user.camelCase(description)
// await tp.user.convertToCamelCase(filename)
await tp.file.move(filename)
-%>
JS Function
async function camelCase(str) {
// Split the input string into an array of words
const words = str.split(' ');
// Check if there's more than one word
if (words.length > 1) {
// Convert the first word to lowercase
words[0] = words[0].toLowerCase();
}
// Convert each word to camelCase
return words.map((word, index) =>
// For words other than the first one, capitalize the first letter
index > 0 ? word.charAt(0).toUpperCase() + word.slice(1) :
// For the first word, keep it lowercase
word
).join('');
}
module.exports = camelCase;