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,702
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