web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Updating Default Site and Warehouse Values on Sales Order Lines

(1) ShareShare
ReportReport
Posted on by 41
Hi All,
Hope all of you having a Good Day, I am currently working on a requirement where,  I need to update the InventDimId field on the SalesLine record based on certain conditions. 
The requirement is if warehouse value is "1", want to update the warehouse to another value e.g. 2 but i am not able to find suitable method as i tried different methods like
validatewrite, updateSalesLineAfterCreate but nothing works.
 
I am unsure if there are any potential issues in my approach that could be causing the InventDimId to remain unchanged.
Any guidance or help will be highly appreciated.
 
 
Thanks and Best Regards..
I have the same question (0)
  • Martin Dráb Profile Picture
    236,289 Most Valuable Professional on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    First of all, when do you want to update the line? For example, you may want to change default dimension values when when a line is created (instead of taking them from the order header), but allow users to change it afterwards.

    Also, what is your version of AX?
  • MA-07051407-0 Profile Picture
    41 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    Hi Martin, 
    Thanks for the response, By default the values are set to Site 1 and Warehouse 1,  Once line is inserted into saleslines, I want to check immediately for the above values, if site and warehouse are 1, i want to update them before actually values are saved into database.
     
    Alternately you can suggest any other possible approaches.
     
    Thanks
  • Suggested answer
    Martin Dráb Profile Picture
    236,289 Most Valuable Professional on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    In F&O, one of the options is extending SalesLineType.initInventDimForInitStorageDimensionsFromSalesTable().
     
    You didn't answer which version of AX you're using, therefore we can't give you anything specific to that (unknown) version.
     
    In general, you should look at the standard initialization logic to understand where you could change that. I started by looking at references of SalesTable.InventSiteId field.
  • MA-07051407-0 Profile Picture
    41 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    Thanks, Martin, for your valuable feedback. Sorry I forgot to mention, I am using D365 FO. Can you please check and update again, or still I have to use the same method you mentioned below?
  • Martin Dráb Profile Picture
    236,289 Most Valuable Professional on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    Moved from Dynamics AX forum.
     
    Fortunately, my answer was already about F&O.
  • MA-07051407-0 Profile Picture
    41 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    I tried the Below method, but no luck. Trying to set some default values but not working.
    I also tried debugger, but this method is not hitting.
     
    class ASalesLineType extends SalesLineType
    {
        
        protected InventDim initInventDimForInitStorageDimensionsFromSalesTable(SalesTable _salesTable)
        {
            InventDim inventdim = salesLine.inventDim();       
           
                inventDim.InventLocationId     = "1";     
                inventDim.InventSiteId         = "1";
            
            return inventdim;
        }

    }
  • André Arnaud de Calavon Profile Picture
    299,069 Super User 2025 Season 2 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    Hi,
     
    You mentioned in your initial question that you have certain conditions for getting a particular site and warehouse. Can you elaborate on what are these conditions about? Is it related to a customer or related to a product? Or something different? Based on the requirement, there are already options to provide some default settings in the application. That can prevent you from developing something already possible. 
     
    Anyway, when looking at your coding, I wonder if you have the correct method to extend. Besides you are missing one really important part to find or create a new InventDim record before you return the inventDim record. You should never try to update an existing InventDim record as you can corrupt the whole inventory transaction storage.
     
    There are various examples in the default application of how to use it. Coding should look like this:
    InventDim inventDim = salesLine.inventDim();       
           
    inventDim.InventLocationId     = "1";     
    inventDim.InventSiteId         = "1";
        
    inventDim = InventDim::findOrCreate(inventDim);
        
    return inventDim;
    Also, ensure that the field InventDimId on the sales line will get the InventDimId value of the found or created inventDim record.

    If you tell more about the "certain conditions", we can help you find the best place to hook in or suggest standard features.
  • MA-07051407-0 Profile Picture
    41 on at
    Updating Default Site and Warehouse Values on Sales Order Lines

    Hi Andre,
    We have warehouses in different countries; I want to check the customer country of origin, and based on that, I want to set the site and warehouse for that particular country in the sales lines. For each Country, the site name is basically the country name and one warehouse. for perticular Site. So once a line is inserted, SO will check the customer country and set the site and warehouse values directly in the sales lines.

     

     

     

    Thanks 

  • Raj Borad Profile Picture
    1,337 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    I think you can use insert method() of salesline:
     
    if (conditions of the country of customer account of salesorder)
    {
    InventSiteId newSiteId;
    InventLocationId newWarehouseId;

    // Set the site and warehouse based on the country
    switch (Country ID of Customer)
    {
        case 'US':
        newSiteId = 'US-Site';
        newWarehouseId = 'US-Warehouse';
        break;
        case 'DE':
        newSiteId = 'DE-Site';
        newWarehouseId = 'DE-Warehouse';
        break;
        // ....
        default:
        newSiteId = 'Default-Site';
        newWarehouseId = 'Default-Warehouse';
        break;
    }

    this.InventSiteId = newSiteId;
    this.InventLocationId = newWarehouseId;
    }
     
    then call super() in insert method.
  • André Arnaud de Calavon Profile Picture
    299,069 Super User 2025 Season 2 on at
    Updating Default Site and Warehouse Values on Sales Order Lines
    Do you have multiple delivery addresses per customer in a different country? If not, you can default the site and warehouse on the customer master. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,188

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 868 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans