Calling text input from prompts

Hi again,

I’m using a meeting template as an action. I have two prompt steps before the template step that ask for “Company” and “Topic”.
Both the Key and Title are the same, so in the Company prompt the Key and Title are both “Company”. In the Topic prompt the Key and Title are both “Topic”.
Then within the body of the template i have added [[Company_text]] and [[Topic_text]], but it’s not pulling the data through, just the code.

As usual, any help would be appreciated!

Can you share your action? It is a lot quicker and easier to see what’s going on when we can see all of the details.

Hi, sorry for the delay.

Shared below -

drafts5://action?data=%7B%22uuid%22:%2273227671-AD8B-4E44-BB95-BD836E7263C3%22,%22steps%22:%5B%7B%22platforms%22:3,%22data%22:%7B%22promptKey%22:%22Company%22,%22includeTextField%22:%22true%22,%22includeCancelButton%22:%22true%22,%22promptMessage%22:%22%22,%22promptTitle%22:%22Company%22,%22textFieldDefault%22:%22%22,%22promptButtons%22:%22OK%22%7D,%22type%22:%22prompt%22,%22isEnabled%22:true,%22uuid%22:%226EBD865F-6BFD-4D6F-9EBA-09DC84EFD0B0%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22promptKey%22:%22Topic%22,%22includeTextField%22:%22true%22,%22includeCancelButton%22:%22true%22,%22promptMessage%22:%22%22,%22promptTitle%22:%22Topic%22,%22textFieldDefault%22:%22%22,%22promptButtons%22:%22OK%22%7D,%22type%22:%22prompt%22,%22isEnabled%22:true,%22uuid%22:%22D4685476-17E8-46EB-87C9-2BC054BB1DF7%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22script%22:%22%5C/%5C/%20create%20template%5Cnconst%20template%20%3D%20%60%23%23%20Meeting%20Notes%20%5B%5Bdate%7C%25d-%25m-%25Y%5D%5D%5Cn%5Cn-%20Company:%20%5B%5BCompany_text%5D%5D%5Cn-%20Topic:%20%5BTopic_text%5D%5D%20%5Cn-%20Attendees:%5Cn%5Cn%23%23%23%23%20Minutes%5Cn%5Cn%23%23%23%23%20Actions%5Cn%5Cn%60;%5Cn%5Cn%5C/%5C/%20create%20the%20draft%5Cnvar%20d%20%3D%20Draft.create();%5Cnd.content%20%3D%20d.processTemplate(template);%5Cnd.addTag(%5C%22meeting%5C%22);%5Cnd.update()%5Cn%5Cn%5C/%5C/%20load%20in%20editor%20and%20focus%20for%20editing%5Cneditor.load(d);%5Cneditor.activate()%22%7D,%22type%22:%22script%22,%22isEnabled%22:true,%22uuid%22:%222A592514-D457-4935-9B18-E363BAA4BA02%22%7D%5D,%22groupDisposition%22:0,%22shortName%22:%22Meeting%22,%22shouldConfirm%22:false,%22disposition%22:3,%22keyCommand%22:%7B%22optionKey%22:false,%22input%22:%22%22,%22controlKey%22:false,%22commandKey%22:false,%22type%22:%22action%22,%22discoverabilityTitle%22:%22Meeting%20Template%22,%22shiftKey%22:false%7D,%22logLevel%22:2,%22notificationType%22:2,%22tintColor%22:%22none%22,%22actionDescription%22:%22Create%20a%20new%20draft%20pre-filled%20with%20template%20content,%20and%20already%20assigned%20a%20%E2%80%9Cmeetings%E2%80%9D%20tag.%22,%22keyUseIcon%22:false,%22icon%22:%22memo%22,%22visibility%22:2,%22groupUUID%22:%22E0B588CF-438C-4D42-A444-0A7A49CA87B3%22,%22assignTags%22:%5B%5D,%22name%22:%22Meeting%20Template%22%7D

At the end of the Drafts documentation on prompts is the following line


If you wish to use the results of prompt in an script action step, you can retrieve the values using the draft.getTemplateTag('tagName'); function.


This indicates that the way the script action accesses the prompt template tags is by an initial retrieval step; a bit different as to how it is in other action steps. If we add a couple of these retrievals in at the start of the script step and then substitute those into the template constant setting, we get something like the script below.

Note: You can also grab an updated copy of the action here.

// evaluate the prompt entries
let company = draft.getTemplateTag('Company_text');
let topic = draft.getTemplateTag('Topic_text');

// create template
const template = `## Meeting Notes [[date|%d-%m-%Y]]

- Company: ${company}
- Topic: ${topic} 
- Attendees:

#### Minutes

#### Actions

`;

// create the draft
var d = Draft.create();
d.content = d.processTemplate(template);
d.addTag("meeting");
d.update()

// load in editor and focus for editing
editor.load(d);
editor.activate()

Hope that helps.

1 Like

Perfect, thanks.

Love this community! I’ve never done much programming, but picking up useful real world examples in this forum really helps!

1 Like