Help needed with misbehaving action steps


#1

I’m sure the “misbehaving” is user error, but…

I’m trying to build an action that takes a couple of prompts and uses the results in an email, but I’m missing something very important.

My current action will not correctly insert the prompts and other text (via Insert Text step) before creating the email. The email is ending up with whatever was previously on the screen (blank email from a new draft, previous text if there was a draft open when the action was triggered).

I thought that the first step in my action list (the script that creates a new draft) would be sufficient to set the stage. I’m obviously missing something here.

Any help would be greatly appreciated.


#2

If you just want to send the email, you don’t need to create a new draft (1st script action). Cut everything out of the insert text action and paste it into the mail action.


#3

Thanks for the input.

I don’t want to only sent the email. I’m hoping to incorporate additional steps in the future including appending some of the information to a Dropbox file, etc.

I’ve used the method you’ve suggested in one of my earlier versions, but realized that I can’t use Markdown unless I use the %%[[draft]]%% + HTML in the email stage (this is also for future implementation) so blasting the variables straight into a Mail step isn’t the best way to go for my use case.

I really want to end up with a draft that stands on it’s own (and can be dealt with in other ways) and a sent email from that draft.


#4

You could put it into the clipboard with an action and then insert the clipboard into a draft and an email.

Or you could do it all in javascript.


#5

Again, thanks for your input, but what I’m really looking for is a way to understand what I’ve done wrong in the action I created; from my perspective, the action I created should work.

I’m really hoping someone can explain to me where the error is occurring. That way I can learn how to solve it rather than just seeking another path.


#6

It looks to me like the draft only updates the content when the action finishes. Resulting in this. Maybe @agiletortoise can confirm?


#7

I had a similar occurrence during the original beta testing, but of course Greg was able to clarify what was going on.

Here’s how he explained it to me in the context of my query:

Loading a new draft in the editor does not change the draft that is in context for the execution of the action.

Think about the possibility of multiple actions running concurrently. If you start an action on a draft, the “draft” variable points to that draft. So you have created a new draft in your first step, and loaded it in the editor, but “draft” still refers to the draft you ran the action on.

Therefore, where possible, work with the draft rather than the editor. However if you use the insert text action rather than script a text insertion into the draft. You come a little unstuck as you found.

In that scenario, rather than using the draft content you can use the editor content for your mail. There isn’t a template tag for this, but you can create one with a line of script.

Hope that helps.


#8

Thank you so much!
I was totally not considering the draft vs editor content issue.
The revision of my action works exactly as intended (once I re-activated the initial script to start with a blank draft in the editor).

Cheers!


#9

A quick update - I’ve realized that when using your solution, the “After success = Archive” won’t act as expected as it will archive the previous draft since I am working with the editor content and not the actual draft. Your explanation of @greg-pierce’s original explanation is making much more sense as I flail my way into more problems.

My quick and easy answer for this issue will be to split the workflow into two reasonable actions;

  1. create a draft
  2. mail it

#10

I would actually say that it does do what is expected based on the information above.

Rather than splitting the action as you suggest, what if you made a split after the mail and called it automatically to effectively keep it one touch workflow? Sounds a bit crazy doesn’t it? Here’s what I mean (based on a quick test that seemed to work for me).

I have an action that no steps. When it runs however it will archive a draft because of its setting. I rarely auto archive drafts and I find it a handy addition to my actions on occasion.

Given that we can have a separate archive action like this it would be great if at the end of your mail step we could just add something that tells Drafts to archive the new draft that was created as part of this action. The issue you came across is that the action is going to work on the original draft not the new one.

What we need to do is queue up an archive action to work on the new draft.

In your first script step the new draft s defined as ‘d’. Let’s say our archive action is simply called ‘Acrhive’. Adding an additional script step at the end of the action and including the statement below along with any conditional logic to trigger it I think should then cover off your archiving need.

app.queueAction(Action.find("Archive"), d);

Give it a try and let me know if that works for you. I’ve only done a quick test of the principle, but it seemed to work for me.


#11

Not sure what the current state of the action is, but it’s easy to archive a draft in a script:

// assuming ‘d’ is a var pointing at your new draft
d.isArchived = true

You can do that as soon as you create the draft if that’s where you want it to be, not need to wait until the other stuff is run.


#12

Thanks for this input! This works great!


#13

Works great; thanks for the super-short script solution!

More and more I’m realizing that, at some point, I’m going to need to lock myself in a room with JavaScript for Dummies. :wink: