New calculated attribute operator - INTERPOLATE (v.23)

Starting with version 2023, calculated attributes now support a new operator - INTERPOLATE.

This is another way you can take advantage of string interpolation in ERP.net.

You can think of INTERPOLATE operator as a composition of others- GET(OBJ)VALUE, CONCAT, CAST, FORMATSTRING.

But on steroids!

Usage

Using INTERPOLATE is quite simple. The most common way is to simply pass a single CONST parameter containing the interpolated string you want to evaluate.

E.g.,

10: INTERPOLATE: CONST: Hello {Id}

The {Id} will be replaced with the corresponding value of the Id attribute.

 

Here's a little more complex scenario (let's assume that our calculated attribute is defined in the Crm.Customers entity),

10: INTERPOLATE: CONST: {DefaultPaymentAccount.BankAccount.BankName}

This way you'll get the name of the bank serving the customer's default payment account.

What's the point?

Well, you can achieve what's described in the usage examples from above with other operators as well, such as GET(OBJ)VALUE, CONCAT, CAST..

But where INTERPOLATE operator shines is in its simplicity.

Do you remember this post?

https://support.erp.net/hc/bg/community/posts/360005093920

In short, it explains how you can create a calculated attribute "Historical data JSON".

Yes, it returns a JSON formatted string and the CA definition contains 22 expressions. Twenty two.

Using the INTERPOLATE operator, you can achieve the same thing with an "one-liner":

10: INTERPOLATE: CONST: {{"receiptNumber":"{SalesOrder.@RN}","receiptDateTime":"{SalesOrder.@RD}T00:00:00","receiptAmount":{SalesOrder.@RA},"fiscalMemorySerialNumber":"{SalesOrder.@FMSN}","uniqueSaleNumber": "{SalesOrder.@USN}"}}

By the way, do you remember how you can get the description of a custom property?

This is no longer a case:

10: INTERPOLATE: CONST: {@CustomerProperty:d}

And that's all. One-liner again.

This is string interpolation

The examples above are a very small part of what's possible with string interpolation and therefore the new INTERPOLATION operator.

Besides that, you can now very easily follow entity references, here's what else you can do:

  • You can format the value of an attribute, using format specifiers.
  • Use of system variables such as $user, $enterprisecompany, $datetime, so you can put some "current user context" in your CAs.
  • Get an object directly without using the FIRST, SELECT and WHERE operators combination.

And more.. check our documentation for more info,.

---

More information is available in our official documentation:

https://docs.erp.net/tech/advanced/calculated-attributes/operators/interpolate.html

https://docs.erp.net/tech/advanced/string-interpolation/index.html

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk