Loops in Notification Templates

Hi Everone,

There is a nice functionality in Acumatica that allows you to print details of the document inside the notification template.
Acumatica Notification Templates

Together with other Data Fields, now you can put additional constructions like Loops (or for-each loops)

<foreach view="Products"> 
    ((Products.InventoryID)) - ((Products.Quantity)) - ((Products.CuryExtPrice)) <br> 
</foreach>

Here you can find following important elements:

  1. ((Products.InventoryID)) – is link to the data view and field. You can use designer to insert fields like this using button “Insert” -> “Data Field” Acumatica Notification Data Fields
  2. <foreach> – here it is the reserved word for the beginning of the loop
  3. view=”Products” – this is a view name that is used to get data from database. You can find a view name from “Inspect Ellement” customization tool or from other Data Fields. Data field has format like “((Products.Quantity))” – here “Products” is a view and “Quantity” is a field.
  4. </foreach&gt – is the reserved word fro the end of the loop. Everything what is between beginning and the end will be repeated by number of the details in the document.

You can read little bit more about it this functionality in the Acumatica help.
Note that you can use all possible HTML within a foreach loop.

Setting up approval notifications in Acumatica

Here I would like to share with you my own experiments. I wanted to print claim details inside standard notification template. To make it nicer I also added borders around lines and high-lighted the line amount.

  1. First Step is to Setup Notification Template. For the beginning you can use simple construction like this for details.
    <foreach view="EPExpenseClaimDetails"> 
        ((ExpenseClaimDetails.InventoryID)) - ((ExpenseClaimDetails.TranDesc)) - ((ExpenseClaimDetails.CuryExtCost))   
    </foreach>

    Later you can do more experiments and make HTML nicer.
    Acumatica Notification Loop

  2. Second Step is to setup Notification and Approval workflow in the appropriate module settings.
    Acumatica Expense Claims Approval Notification
  3. Third point is to create a claim and submit it. Please note that claim should meet your approval notifications.
    Acumatica Submit Claims
  4. As soon as you submit a claim, notification should be generated and you can see it on the “Emails Pending Processing” or “All Emails”.
    Acumatica Expense Claim Email

Formating in the Loop

As soon as this is solved you can continue with some more nice experiments. Here I have tried to add borders and put every single line in the box with CSS styles. Border shadow is needed to collapse inner borders between divs.

<div>
     &lt;foreach view="ExpenseClaimDetails"&gt;
         <div style="border-width: 0px; border-style: solid; width: 700px;
		 		box-shadow: 1px 0 0 0 #888, 0 1px 0 0 #888, 1px 1px 0 0 #888, 1px 0 0 0 #888 inset, 0 1px 0 0 #888 inset;">
             <span data-field="yes">((ExpenseClaimDetails.InventoryID))</span> - 
			 <span data-field="yes">((ExpenseClaimDetails.TranDesc))</span> 
			 <span style="float: right;">
			     <span data-field="yes"><b>((ExpenseClaimDetails.CuryExtCost))</b></span>
			 </span> 
         </div>
     &lt;/foreach&gt;
</div>

Have a nice notifications!

18 Replies to “Loops in Notification Templates”

    1. Hi Therese,
      Do you need a notification for ACH? Screen Batch Payments can generate ACH file with the proper format, should you just send vendor a file?

  1. Hi
    How did you get the data fields formatted properly as numbers? I am displaying fields from a Generic inquiry in a notification, but the GI formatting is not being preserved nor can i use rounding.

    So instead of for Sixty Thousand, One Hundred and Thirty Two dollar and 12 cents i am getting 60132.1266667 instead of 60,132.12

    1. With the GI as the business event screen, the FOR loop just repeats the first line of the GI for every row of the GI results. Any idea how to utilize the for loop for a GI based business event?

      1. The solution to the loop issue is to add the view before the GI result even tho the GI result already displays the view.
        Example, if inserting a data field produces “ARTran_unitPrice” , it is still required to edit the field to “ARTran.ARTran_unitPrice”.

        Still haven’t found a solution for the formatting issue.

        1. Hi Ellie, I’m not sure there is a way to format values in the html without customization.
          Only the way that comes into my head is to create a new virtual field with customization that gets the value and format it in the code.
          Than you use this new field in the notification templates.
          Sorry, not an easy way.

      1. Hi Sergey, I am trying to add a table instead of span. Doing:
        Sample
        Value from data

        Every time I save the code changes to:

        Foreach…….>Value from data

        ………

        The fact is that the notification draws a table but only for the last iten

        1. Hi Boris,
          I tried to do table, but due to the fact that you need to repeat only rows, it gets harder. I was not successful with table and wend with span instead.

  2. 1] “foreac h” view=(Products)
    ((Products.InventoryID.ItemClassID.Descr))”BR”
    “/ foreac h”

    2] “foreac h” view=”Products”
    ((Products.InventoryID.ItemClassID.Descr)) “BR”
    “/ foreac h”

    1. Try to use example from this page:
      https://help.acumatica.com/(W(1))/Wiki/ShowWiki.aspx?pageid=ebcda76a-433f-4bde-8aed-efc69474fd03
      Please note that fields have only one level – Products.Quantity
      Can you try this way? And certainly I suggest to move from Automation Notifications to Business Events.

  3. Pre tags did not help – essentially; the foreach loop is not functioning as expected in the Automation Notification email body.

    Please assist.
    Kind regards,
    Christopher

    1. Good morning Sergey.
      Thank you very much for your reply and suggestion – will look into Email Templates with Business Logic.

      ((Products.InventoryID.ItemClassID.Descr))”

      ((Products.InventoryID.ItemClassID.Descr)) “
      “”

      I have broken my examples with “” to force it to show for you.

  4. Hello Sergey.

    This is nice functionality indeed.

    I am experiencing a issue where the loop is not hidden in the message body.
    I have now tried two variants of the foreach loop namely
    1]
    ((Products.InventoryID.ItemClassID.Descr))

    2]
    ((Products.InventoryID.ItemClassID.Descr))

    Please note above that I have encased the view name in braces in case 1] and in quotes in case 2].

    In both scenarios the product list is not rendered in my test emails as the below shows:

    DRY VAN

    DRY VAN

    I am looking forward in hearing from you.
    Kind regards,
    Christopher

    1. Christopher,
      Could you please show me whole foreach loop code. What view are you using in the loop definition?
      Also could you please try to use Email Templates with new Business Events notifications?
      And lastly – I guess it will be good to try to use only one level of fields from first and than make it more complicated.

      Basically I suggest to do iterations from simple scenario to complex scenarios to identify what exactly does not work

Leave a Reply

Your email address will not be published. Required fields are marked *