I’m having a hard time getting a multi-step action to work.
In the first action, I have a script that runs through a few prompts and ends with a draft object that I want to send to a HTML preview. In the HTML Preview, I want the “continue” button to open the draft in the editor, and cancel to just cancel.
Here’s the end of my first script:
let webpage = Draft.find(tagged[a].uuid);
alert(webpage.content);
alert(webpage.uuid);
webpage.setTemplateTag("prev",webpage.content);
webpage.setTemplateTag("link",webpage.uuid);
webpage.update();
The two alerts tell me that the right data is being grabbed.
However, my HTML preview is showing me [[prev]]
instead of the actual text of the draft. Here’s the relevant portion of the HTML preview:
<body>
%%[[prev]]%%
</body>
Lastly, I’m not sure how to script the continue button iff I’m using the HTML Preview action step and not writing it into the javascript itself. Thanks for any help!
Here’s something that may be useful or may be confounding:
If I replace the “setTemplateTag” code with
editor.load(webpage);
and then use %%[[draft]]%%
in the HTML Preview, I tend to get a preview of the draft that was loaded into the editor when I ran the action–not the draft selected by the action.
Does loading a draft in the editor reset the “draft” local variable?
You may be working with another draft, but you need to pass the data with the current draft. That’s the consistent instance.
let webpage = Draft.find(tagged[a].uuid);
//alert(webpage.content);
//alert(webpage.uuid);
draft.setTemplateTag("prev",webpage.content);
draft.setTemplateTag("link",webpage.uuid);
draft.update();
1 Like
Just for my own edification, it is possible to use setTemplateTag
on another draft object, it’s just that I can’t reference that draft object in the HTML Preview action step? Or it always has to be draft.setTemplateTag
?
The preview action is implicitly referencing the current draft - otherwise how would it know which draft to reference; there isn’t an option to specify a different draft.
If you built your preview action as a script you would be able to tell that preview ot use a different draft.
I guess I supposed that when a new draft was loaded into the editor in the script, that the “draft” object was updated or changed in the action flow.
No. The draft object is set at the start of the action call; though if you batch process a set of Drafts from the list, you effectively run multiple action calls. One for each selected draft.
Moving things in and out of the editor will affect the editor instance, not the current draft instance.
1 Like
An action is alway run on a specific draft. No matter what you do in the action, the draft
global variable is always going to point to that draft, and action steps that use templates directly will be evaluating those templates in relation to that draft…so, if you want a subsequent HTML Preview step after your script to use values, you would want to set those template tags on the draft
object.
You can, however, evaluate templates against other drafts within the context of the script, if desired, and, for example, create and display an HTML Preview via script.
Per your example above, you can do:
let webpage = Draft.find(tagged[a].uuid);
webpage.setTemplateTag("prev",webpage.content);
webpage.setTemplateTag("link",webpage.uuid);
let template = `<body>
%%[[prev]]%%
</body>`;
let preview = new HTMLPreview();
let html = webpage.processTemplate(template);
preview.show(html);
``
1 Like