ORDA: Easy looping with a new 4D tag

You have probably already used a For each…End for each loop to work with ORDA entity selections or with collections. Its use is simple and straight forward.  Would like to use it as a 4D tag in your SHTML pages? Or perhaps with the PROCESS 4D TAGS command?

As of 4D v19, you can! Keep reading to learn more.

HDI: 4DEACH tag

A new 4D tag is now available: the 4DEACH tag

Its use is very similar to a For each…End for each loop.

Just a reminder

Here is a simple example to remind you how to use a For each…End for each loop on an entity selection:

var $customer : cs.CustomersEntity

For each ($customer; ds.Customers.all())
 $customer.name:=Uppercase($customer.name)
 $customer.save()
End for each

and now let’s use the new 4DEACH tag

In this blogpost, we showed you how to put some data related to the user in the web session.  For example, a salesperson’s top three customers.

The following is the SHTML code to display these top three customers (Session.storage.myTop3) which is an entity selection.

We can verify the 4DEACH tag allows looping through it.

customers.shtml file:

<table class="table">

<tr><th>Name</th><th>Total purchase</th></tr>

<!--#4DEACH $customer in Session.storage.myTop3-->
<tr>
<td ><!--#4DTEXT $customer.name--></td>
<td ><center><!--#4DTEXT String($customer.totalPurchase;"$###,##0")--></center></td>
</tr>
<!--#4DENDEACH-->

</table>

 

And here is the result:

 

As you can see, the syntax is very similar to a For each…End for each loop.

The tag also works for collections and objects (to loop through an object’s properties).

It’s also supported by the PROCESS 4D TAGS and WEB SEND FILE commands. 

Download the HDI above to play with this new tag and join the discussion on the 4D forum!

 

 

Avatar
• Product Owner • Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.