Thursday, June 30, 2016

Dynamic Text Size and Color in RTC Report | NAV


Never say no when a client asks for something, even if it is the moon. You can always try, and anyhow there is plenty of time afterwards to explain that it was not possible. -Richard M. Nixon


The requirement was for the Report section in Microsoft Dynamics NAV 2016. Some of the contents of the report are to be adjusted into given textbox. The text size was supposed to vary and fit into the given text area. 
For the Example Purpose i have taken Sales Invoice and Ship to Name as a Field. It can be achieved in any Report.

<Scenario>
TEST CASE I: Text length is small - So It can keep its Original Size [14 Pt]



TEST CASE II : Text length is Larder to fit in the area with same Font so it was adjusted to [10]

Note: For the Simplicity i have kept it just to two condition. 14Pt or 10Pt


<Solution>
Its as simple as IF/Else Condition in CAL Code. 

//----------------------------//

Code Syntax:

//Using IIf Condition
IIf(Len(Variable_Value) <= Lenght,“True_Value Pt”,“False_Value Pt”)


//-----------------------------//

Example:

//Using IIF Condition for Size
=IIf(Len(Code.GetData(11,1)) <= 10, “pt”, “16pt”)



Alternative: =IIf(Len(Field!DatasetVar.Value) <= 10, “pt”, “16pt”)
//-----------------------------//

//Using Switch Case for Size

=Switch(Len(Code.GetData(11,1)) <= 10, “14pt”, 

Len(Code.GetData(11,1)) >=11 AND Len(Code.GetData(11,1))<=20 , "10pt", Len(Code.GetData(11,1)) >20 , "5pt")


//Using Switch Case for Color
=Switch(Len(Code.GetData(11,1) <= 5, "Green", 

Code.GetData(11,1) >=10 AND Code.GetData(11,1)<=15 , "Amber", Code.GetData(11,1) >15 , "Red")



//---------------------------------//

Note: We can use the Same type of Code for Color and other related property of Text. 

This small code trick turned out Quite handy to impress the client.
Cheers!!!

No comments:

Post a Comment