The magic of InventDim “AllBlank”

Using the PriceDisc class in Dynamics AX is not always the easiest thing in the world. If you start out with a sales line or a purchase line you got methods that helps you get prices from the trade agreement, but if all the info you have is the ItemId and VendAccount it gets a bit tricky.

My thinking was that I should be able to use the PriceDisc class just as the InventOnhand class. You put in basic info, and the more data you enter into the class the more precise the result gets. But the hurdle I had trouble getting over was that the class PriceDisc requires a record from table InventDim, something that you only get if you start out with a sales line or a purchase line.

The solution to this problem is the InventDimId “AllBlank” which basically means a blank InventDim record with the InventDimId “AllBlank”. What if this InventDimId doesn’t exist? Well that’s why you should use the InventDim table method findOrCreateBlank().

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  server static public InventDim findOrCreateBlank(
                    boolean testConfigurationKey = true)
  {
    InventDim inventDim;
    #define.blank('AllBlank');
 
    if (testConfigurationKey && 
        isConfigurationkeyEnabled(
        configurationkeynum(LogisticsAdvanced)))
          return inventDim;
 
      inventDim = InventDim::find(#blank);
      if (inventDim.RecId)
          return inventDim;
 
      inventDim = InventDim::findDim(inventDim);
      if (inventDim.RecId)
          return inventDim;
 
      ttsbegin;
 
      inventDim.InventDimId = #blank;
      inventDim.insert(true);
 
      ttscommit;
 
      return inventDim;
  }

This method returns the InventDim AllBlank record if it exists and creates it if it doesn’t. Now you should have all the data you need to get information from the trade agreement. The rest of the data required by the new method is rather basic.

Don’t forget that UnitId and currency also need to match to your trade agreement. The currency bit got me frustrated yesterday. Easy thing to forget, but when it comes to the trade agreement all things matter.

Last 5 posts in Development

Leave a Reply

Your email address will not be published. Required fields are marked *