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!

6 Replies to “Loops in Notification Templates”

  1. 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

    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.

  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.

Leave a Reply

Please rate*

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