In this article, we will share some of the most used expressions. If you have one - which is not on the list - please reach out and so we can add it.
How to combine text with D365 fields in Expressions
This example is in D365 LAC Report structure. Follow these steps to combine text with D365 fields in expressions:
In the report structure click the New field where you would want this field placed in the XML - e.g. LNHeaderFields.
Give it a name.
Then in the Expression column, click the + button and select Expression.
Example layout Text "Invoice Id - Invoice#" with actual invoice number in D365
In the expression, click the + button and then select Value and type in the text - Invoice Id
Click out of the box and the value should move to the expression box at the top.
Click the + button.
Start next value -
The same procedure as above
Next Value "-"
In the expression, click +, select Value and type in the text.
Click out of the box and the value will move to the expression box at the top.
Next is the invoice number from D365.
In the expression click on the + button, select Table and then select field from Table.
Click Insert and the value should move to the expression box at the top.
How to show only some text in the string/If field
Hide line field - if line field is the same as a header field
Example on sales confirmation; we have a delivery date on line level and on header level.
On line level - we only want to show those dates which are different from the header date.
Follow these steps:
Find the line field and on the Condition column, choose Code.
Click the Edit button and choose Expression.
In the Expression definition box, paste in the following Expression: If SalesTable.DeliveryDate=SalesConfirmDetailsTmp.DlvDate Then 0 Else 1 and click OK.
Or you can build it by using the If condition and then click Insert:
Result - before
Now No line field - when line field is the same as header field:
(If SalesTable.ShippingDateRequested=SalesLine.ShippingDateRequested Then 0 Else 1)
Show only a limited part of the substring
The following example illustrates how to make a substring of the Purchase-order (Purch-Id). The number sequence is six characters and we only want to show three on the report. Follow these steps:
Create a new Element and click the + button.
Paste in the following expression: SubString ( PurchPurchaseOrderHeader.PurchId , 1 , StrLength ( PurchPurchaseOrderHeader.PurchId ) - 3 )
The purchase Order string is 001568 and the newly created element is 001.
Show one or zero if the field contains the following value
You want to return one when true and zero when false if your delivery term contains "CFR,CIF,CIP,CPT,DAT,DAP,DDP"
Expression: "CFR,CIF,CIP,CPT,DAT,DAP,DDP" Contains DlvTerm_Terms.Code
This will return one if true and zero if false without the need for the If Else statement.
How to replace some text/thing in the string
Replace a word with another word
Some companies use the Proforma invoice or sales confirmation as Export Invoice - therefore they want the title "Export invoice" to replace the title.
Paste or build the expression:
strReplace ( SalesConfirmHeaderTmp.LACOriginalReport_DocumentTitle() , "Confirmation" , "Export Invoice" )
Calculate multiply, subtraction, dividing
Example - LineAmount divided by qty can show the "unit price after discount".
Follow these steps:
Create a new Element and paste in the following Expression:
or build it using the "Select value".