Crop text length

This question is answered

In the ForecastSales table I would like to add a method to return the first three characters of the Customer type (Dimension).

The field length is 10 characters but I want to return the first three

e.g.

GEN01, GEN02, GEN03 would all return GEN

 

display Dimension dimension()
{
    str CustDimTrim;

    CustDimTrim = subStr(this.Dimension,1,3);

    return CustDimTrim;

}

Verified Answer
  • Hello PhilSM!

    In AX 2009, the product shipped with three default dimensions out of the box, Department, CostCenter, and Purpose. So this Customer dimension is most likely a customization that you’ve added. The Dimension Extended Data Type is array based so you’ll need to know which element in the array represents your Customer data. That can be found by browsing to the following node in the AOT:

    AOT\Data Dictionary\Extended Data Types\Dimension\Array Elements

     

    Once you know which element of the array represents that Customer data, you can use the following code below, by replacing ‘x’ with that index. Also note, I’ve modified the return type of the method to simply ‘str’, as we only want to return a string.



    public
    display str dimensionPrefix()

    {

        str customerPrefix;

       

        // Only grab the first three characters of the customer dimension

        customerPrefix = subStr(this.Dimension[x], 1, 3);

       

        return customerPrefix;

    }

All Replies
  • Hello PhilSM!

    In AX 2009, the product shipped with three default dimensions out of the box, Department, CostCenter, and Purpose. So this Customer dimension is most likely a customization that you’ve added. The Dimension Extended Data Type is array based so you’ll need to know which element in the array represents your Customer data. That can be found by browsing to the following node in the AOT:

    AOT\Data Dictionary\Extended Data Types\Dimension\Array Elements

     

    Once you know which element of the array represents that Customer data, you can use the following code below, by replacing ‘x’ with that index. Also note, I’ve modified the return type of the method to simply ‘str’, as we only want to return a string.



    public
    display str dimensionPrefix()

    {

        str customerPrefix;

       

        // Only grab the first three characters of the customer dimension

        customerPrefix = subStr(this.Dimension[x], 1, 3);

       

        return customerPrefix;

    }