Send email with pdf attachment by button So I...

Send email with pdf attachment by button So I finally got a report with pdf attachment with pictures working pretty well (thanks for all the help!). Right now it’s just a report on a schedule, with the template start statement <<Start:SELECT(Properties[BlitzKey], true, true)>> and “With These Rows” value in the report set to “only send once”

I need a very similar “report” (probably will be a workflow actually) to be sent by a button in a slideshow. I think that button has to modify a field, which then will actually trigger the workflow. At first this seemed sort of stupid, but then I realized if I used the button/action to increment a “reports sent” column, that’s useful info. If I set up the workflow with a “If this is true” condition something like [_ThisRow_Before].[ReportsSent]<[_ThisRow_After].[ReportsSent], then other row changes won’t trigger the workflow.

Also, I only want to send the current row, which I think entails changing my condition statement for the workflow to a slice including only _ThisRow… I haven’t worked with slices yet.

I’m sort of thinking out loud here, and hoping to check my thinking: is this a reasonable way to go about this? Have I missed something? I haven’t worked with actions or workflows yet either (it’s amazing how far you can get in this platform without knowing anything), so perhaps I’m being unduly cautious. Thanks!

0 31 4,670
31 REPLIES 31

@Keith_Winston

I am not sure I am following.

I am assuming you would use an event triggered workflow rule. In this model, the user is looking at a particular table record. They then do something that updates a field in that record. They could either explicitly change a field value, or they could click a button that invoked an action that changes a field value.

When that change is synced to the server, the event triggered workflow rule is invoked. It generates and sends the email. It can base that email on the data values in the updated record. One sample illustrates the case where the email recipient is specified in the updated record. Another, illustrates the case where the user selects specific PDF attachments to include with the email.

I got lost when reading the last two sentences in your message. I don’t think you need a slice to do this but I may be missing something.

@Keith_Winston

This article shows how to do this help.appsheet.com - Triggering Email, SMS, or Notifications from the App

Triggering Email, SMS, or Notifications from the App help.appsheet.com

Thanks Phillip. I was sort of building off of that. I want them to be able to send an email even when they have no update or change to the data, so I am creating this new column ReportsSent. I’m excluding other changes by only counting increments in that column.

Right now I’m stuck at the “send a email/workflow/report based only on the current row” part. I can’t figure out how to set up a slice that only looks at the current row.

@Keith_Winston

That sounds perfect for an Event Triggered workflow rule.

When you click the button on the client, it can update the value of a field in the record.

When the user does the sync, that single updated record is sent to the server.

The server will save the update and notice that there is an Event Triggered workflow rule for that table that should be triggered on update.

You can write a condition on the rule to check for specific field values in the updated record. This allows you to trigger the rule in some cases and not others.

The workflow rule will be invoked and your workflow rule logic can directly reference the fields from that single updated record. It can simply uses the names of the fields because it know exactly which record is being updated.

You can create the PDF attachment and send the email to the appropriate person.

@Keith_Winston

If this is not clear send me an email at philga@appsheet.com

It’s pretty clear but I might need a little more hand-holding… for example, I don’t immediately see how to “write a condition to check for specific values” when the specific values I’d most like to access is _thisrow_before and _thisrow_after: I know I saw that somewhere in your documentation, but for some reason it doesn’t come up in a search of support… That is (as stated above): what’s the ACTUAL CODE for a condition that filters a workflow to only use those records that have changed from before & after it was fired… or is that not possible? Is that information already lost when the workflow is triggered? In which case this has all gotten hard again.

[note that my slice approach may be the wrong approach, fyi]

Hmmm: specifically, perhaps if I want an workflow to only act on the current row, I should/could set that up in the template Start statement? I can see how that might work, though I’m still uncertain of the exact language in my Start statement.

If you are using a event triggered workflow rule that acts on a single row, I am not sure why you need a Start statement at all.

Maybe we should start over. What are you trying to do?

I think I don’t know how to set up a workflow rule that acts on a single (and in fact, the current) row. And haven’t been able to figure it out for a couple hours (well, I’ve been doing a few things at once, in my own defense).

I think I also have to limit it to only acting if the ReportsSent column is incremented, and I haven’t been able to test that since other things aren’t working. As I type that, it occurs to me that I could use that to identify the “current row” : that is, if the action is incrementing a value, the workflow can work on any rows whose after values are > before values. I’m going to try that, but for the record how else can one arrange a workflow to only act on the current row? This is why I was going to create a slice, but I didn’t figure that out either.

@Keith_Winston

Not a criticism. I am just a little lost.

The idea behind an Event Triggered workflow rule is that it is invoked when a single record is added, updated, or deleted. The act of syncing that add, update, or delete automatically invokes the workflow rule.

When your workflow rule is invoked, it is referring to that single record. You can directly access the fields in that that record by simply using their field name.

A Report or Scheduled rule is different because it normally acts on a set of records. You use the Start expression to select the set of records and iterate through them.

An Event Triggered rule is simpler because it always starts with a single record. Namely the one being added, updated, or deleted.

Sorry, didn’t see your “trying to do?” question. I want a button on the slideshow view (I’ve got that) that triggers a workflow that sends an email that has an attached pdf that is “built” by template using the current row, only. Easy-peasy, right?

@Keith_Winston, thanks a TON for striving to get an answer to this. @Phil, I am with Keith here and just dying for a simple answer to, the question, what is the set of expressions that allows an app user to:

  1. Hit a button (for example “Save and Email”
    *When that happens, then…
  2. Pull all updates from the new row in the Google Sheet (for example “New PDF for You”)
  3. Format them nicely (using a Google Form let’s call “Nice PDF Form”)
  4. Open the user’s email with a new Subject (let’s assume that it the the Sheet’s cell “?C” where the ? represents the row they have open in the app. So if that cell is C:9 and the value in C:9 is “WOW” then the subject of the email would automatically be “WOW”)
  5. Attach the newly created document (the nicely formatted into a PDF for updates to row “C”)

Sounds like similar requirement as this ones.

My old Start statement for the working Report process was

<<Start:SELECT(Properties[BlitzKey], true, true)>> (it selected the entire table)

OTOH my Condition statement for the Workflow is:

[_THISROW_BEFORE].[ReportsSent]<[_THISROW_AFTER].[ReportsSent] (it selects only the changed row, and only works if I disable the Start statement).

The target data for the Workflow is the Properties table.

Please note, I don’t need the And(isnotblank()) machinery, it doesn’t make a difference as noted in prior posts.

The child and grandchild statements in the template fail if I take out the Start statement, and the Condition statement is ignored (the “row selector”) if I leave the Start statement in.

That’s as concise as I can state this I think. I think I only need one of them, and it needs to be different. I can’t tell how, yet.

In conjunction with all this, I’ll say that the Expression Builder doesn’t help with _ThisRow or the before/after question. I’m still searching through your documentation, page by page, trying to find that reference.

@Keith_Winston

See topic “Sending Email When a Row is Updated to Have Specific Values” in this article help.appsheet.com - Triggering Email, SMS, or Notifications from the App

Triggering Email, SMS, or Notifications from the App help.appsheet.com

Argh! I JUST found that after hours of searching. I don’t yet understand how to find information about something like, for example, _ThisRow_Before, without a ridiculous search process or shear luck. It should be searchable… still, thank you very much for the help.

I am still failing at having a workflow only send the row that has changed in the process of triggering the action. I’ve got Condition =

[_THISROW_BEFORE].[ReportsSent] < [_THISROW_AFTER].[ReportsSent], but it sends me all the records. I can’t figure out how to limit it to the one record. Perhaps < doesn’t work, since _ThisRow_After might be weird for rows that didn’t change, and maybe that’s what is meant in the “Triggering Email” link above (that’s not very clear). But even with the Not(IsBlank stuff, it’s not working. That is, maybe one has to use <>, and can’t use <, with _Before & _After.

However, to finish that thought, <> doesn’t work either.

Just for kicks, I moved the expression into the template, but that doesn’t work: the ReportsSent is not the “key” column, and also it can’t find the _ThisRow_After column. I didn’t expect this to work, but there’s nothing like desperation to drive creative, sloppy thinking.

Hours later, one little step forward: IF I have a workflow _ThisRow_Before/After rule, it gets “overruled” by my <<Start…>> statement in my template. I only figured this out by looking at the template of the ClickToSendEmail example. However, I have a lot going on in my template (child tables or whatever you call them) so they all break in the absence of my high-level Start. Any further help will be appreciated. The example template in ClickToSendEmail is too simple to be helpful in illustrating this issue.

The problem is this formula [_THISROW_BEFORE].[ReportsSent] < [_THISROW_AFTER].[ReportsSent]. When the ReportsSent is blank, the app will give you TRUE (because of blank against blank). You should change that formula like… AND(ISNOTBLANK([ReportsSent]),[_THISROW_BEFORE].[ReportsSent] < [_THISROW_AFTER].[ReportsSent]) and it should work.

Thank you but no, Aleksi, that’s not the problem. I have used the formula, but I don’t need it: one of the two fields is guaranteed to be non-blank. In any case, that part isn’t where it’s breaking: the problem is that, apparently, if I try to send only one record to the template BUT the template has a Start statement that doesn’t have the Before/After clause (maybe I can just add that to the Start statement, hadn’t thought of that), then the Start overrides the Before/After Condition in the Workflow. I know this because as soon as I removed the Start, it started working. I got the idea to remove it because that’s how your ClickToSendEmail template is set up. So I’m left with the problem that I can trigger a template to be sent with only the current record, but only if it doesn’t have a Start statement, and if that’s true, it can’t have any Children Start statements/child tables/fields from related tables. Which breaks everything I’m trying to do.

Okay… one easy way is this… add a datetime column (ReportSent) and then create an action button with an epression NOW(). With the workflow condition AND(ISNOTBLANK([ReportsSent]),[_THISROW_BEFORE].[ReportsSent] < [_THISROW_AFTER].[ReportsSent]) you can then send the email.

When you add a new record, your initial value should be blank and it will keep the column’s value as blank. Next time when you open the record from the detail view and you press the action button, it will write the datetime value and the email is sent.

Aleksi, I really appreciate your help, but you’re not yet on point. I’ve got that entire part working. I can get the email sent. I can get the before/after working. That’s not the problem: to do so, I’ve got to break my template. Here’s the issue: I need 1) a multi-level templated email sent that 2) only relates to the current record.

Before, my (highest-level) template Start statement sent a report involving the entire table. Now I want it only sending the “current” record (which is what the Before/After statement selects). However, it is a complicated template, with 3 levels of Start/End (this template works perfectly, when I use it on the entire table). When I use the before/after statement, the template START overrides the before/after (so the template still returns the entire table): Only by removing the Start entirely, just like the template you provide in your “ClickToSendEmail” example (which has no Start statement) does the before/after successfully select for the record I want. Great. Now I’ve got just the record I want reporting. The problem is that if I remove the top level Start (in a template with 3 levels of Start/End), the entire Template breaks. If I put the Start back in, the Before/After (single-record selector) breaks. I need both. Does that make sense? I realize it’s a very nit-picky problem.

It may be that I can change my Start statement, but I haven’t found an example of this and, in fact, can’t put my finger on general overview info on the Start statement. So I don’t know if I can put the Before/After selector in there: since I don’t understand EXACTLY where the front-end/back-end line is, or something, I can’t tell if the template START can do the Before/After test (since it would have to be able to get the before/after values, but those were associated with an Action, which changed a field, which triggered a Workflow, which used the Template: can that Template still see both Before & After values, to make the comparison?).

Ok, I’ve beaten this poor horse enough. Any attempts at help are still appreciated. Thank you.

@Keith_Winston

I think you are getting really close.

If I understand you correctly, you should remove the top level Start expression and leave the two embedded Start expressions. This assumes that the outer Start expression in your Report is selecting records from exactly the same table that your Event triggered workflow is triggered by.

Here is the logic.

When you write a Report (aka Scheduled) workflow rule, your outer Start expression must select the set of records to be displayed.

For each record in the outer set of records, you can include an embedded Start expression to select the child records you wish to display for each of the outer parent record.

If you have a multi-level hierarchy consisting of parent, child, and grandchild records, you can repeat this pattern for each level in the hierarchy. So for each child record you can include an embedded Start expressions to select the grandchild records you wish to display for each child record.

An Event triggered workflow rule template is exactly the same as a Report template except for the outer Start expression. For a Report template, you must write a Start expression to select records from a single table. For an Event triggered workflow rule, you always start with a single record from a single table. If the Report workflow rule and the Event triggered workflow rule start with the same table, then the only differences in the templates is that: 1. The outer start expression is not needed in the Event triggered workflow rule.

  1. You are always starting with a single record in an Event triggered workflow rule , rather than a set of records in a Report workflow rule, so the outer part of your template is only formatting the data values from that single record.

The Start expressions and embedded templates for the child and grandchild records are the same for both the Report and Event triggered workflow rules.

Hmm, we’ll, what I did to try to get it working was just remove the outer start expression, and the fields associated with the topmost record worked. All the child & grandchild fields broke, though, and I had the impression that it was because the embedded start statements had to work off that high-level statement. You make an interesting point, but it appears not to work exactly that way. I agree that I might be very close. Is there any doctoring of the child starts or something that might do it? I’ll look at it tomorrow some more. I also can’t really figure out if there are any debugging tools that help in this particular little part. Thanks for your thinking, I’m going to read through it more carefully tomorrow. I sort of have to get this working tomorrow morning.

Hi Keith,

If you want to trigger a workflow by clicking a button see topic “Sending Email from an Action Button” in this article https://help.appsheet.com/en/articles/961707-workflow

It explains how to do that.

Hi Casey,

If I understand your question correctly, you can achieve that by simply creating a workflow rule that is triggered on Add.
No expression or button is required,

Do this as follows:
1.Open your app in the Editor.
2. Go to the Behavior > Workflow pane
3. Click “Add a new workflow rule”
4. Under “When this happens” set “Target data” to your table name.
5. Under “When this happens” set “Update event” to “Add”.
6. Click the “Save” button on the top right of the Editor. (It is even better to choose “Save and Verify Data” by clicking the down arrow to the right of “Save” because that verifies your workflow rule.)

Now add a record to your table through your Appsheet application. When the new record is synced to the server, your new workflow rule is triggered. You will automatically get an email.

If you want to include a PDF attachment in your email, do the following:

  1. In the “Attachment Content Type” drop down select “PDF”
  2. Click the “Create” button to the right of “Attachment Template” (The button will only appear after you have saved the workflow rule at least once.)

Now add a record to your table. When the new record is synced to the server, your new workflow rule is triggered. You will automatically get an email with a PDF attachment. The attachment will list the fields in your newly added record.

If you wish, you can then start tweaking the attachment template to make it look better.

Top Labels in this Space