Skip to main content

Converting item type in D365 through code

 Well recently I came across an issue where user had created more than 100 items in productions with wrong type. The standard out of the functionality does not allow to convert the item type if its released. Deleting is also not possible. So we are stuck with an option of disabling the item and creating new once with correct type.

But the limitation here is than we would have to come with new sku code where its similar to original code but not exact as it is used. So I wrote the code convert the item type through X++ which resolved our issue.

Below is the code to perform this task.

I am using csv file to bulk update the items and changing item type from service to item in this example.


public static void main(Args _args)

{

        AsciiStreamIo                                   file;

        Array                                           fileLines;

        FileUploadTemporaryStorageResult                fileUpload;


        InventTable invt;

        EcoResProduct ecores;

        ItemId id;

        EcoResStorageDimensionGroupItem EDM;

        EcoResTrackingDimensionGroupItem         ETD;

        InventModelGroupItem         IMG;

        InventTableModule         ITM;

        WHSInventTable WHS;

        PurchLine PUL;

        RefRecId         STD;

        RefRecId         TTD;   

        str purchids;


        fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

        if(fileUpload != null)

        {

            file = AsciiStreamIo::constructForRead(fileUpload.openResult());

            if (file)

            {

                if (file.status())

                {

                    throw error("@SYS52680");

                }

                file.inFieldDelimiter(',');

                file.inRecordDelimiter('\r\n');

            }

            container record;

            while (!file.status())

            {

                record = file.read();


                STD = EcoResStorageDimensionGroup::findByDimensionGroupName('STOCK').RecId;

                TTD = EcoResTrackingDimensionGroup::findByDimensionGroupName('SE').RecId;

           

                if (conLen(record))

                {

                    id = strFmt("%1",conPeek(record,1));

                    invt = InventTable::find(id,false);

                    if(invt.RecId != 0)

                    {                       

                            ttsbegin;

                            ecores = EcoResProduct::find(invt.product,true);

                            ecores.ProductType = EcoResProductType::Item;

                            ecores.update();


                            EDM = EcoResStorageDimensionGroupItem::findByItem('DAT',id,true);

                            EDM.StorageDimensionGroup = STD;

                            EDM.update();


                            ETD = EcoResTrackingDimensionGroupItem::findByItem('DAT',id,true);

                            ETD.TrackingDimensionGroup = TTD;

                            ETD.update();


                            IMG = InventModelGroupItem::findByItemIdLegalEntity(id,'DAT',true);

                            IMG.ModelGroupId = 'STK-ACCES';

                            IMG.update();


                            ITM = InventTableModule::find(id,ModuleInventPurchSales::Purch,true);

                            ITM.TaxItemGroupId = 'STD-G-5%';

                            ITM.update();


                            ITM = InventTableModule::find(id,ModuleInventPurchSales::Sales,true);

                            ITM.TaxItemGroupId = 'STD-G-5%';

                            ITM.update();


                            ITM = InventTableModule::find(id,ModuleInventPurchSales::Invent,true);

                            ITM.TaxItemGroupId = 'STD-G-5%';

                            ITM.update();


                            WHS = WHSInventTable::find(id,true);

                            WHS.UOMSeqGroupId = 'EA';

                            WHS.update();


    ttscommit;

                            info(strFmt("%1 - Update",id));                      

                    }

   else

                    {

                        info(strFmt("%1 - Notfound",id));

                    }

                }

            }

            info("done");

        }

    }

Comments

Popular posts from this blog

Error 500 on the server for D365 finance and operations

While working on D365 finance and operations one fine day i came across the error 500. There are many reasons for this server. Below link can help you if encounter the same issue. https://community.dynamics.com/ax/f/33/t/195422 If any of solutions does not work for you then you might need to check if there are any newly added objects through code and they might be causing the issue. Try to remove them build and synchronize them with the database. https://community.dynamics.com/ax/b/axdilip/archive/2017/01/05/dynamics-365-for-operations-troubleshooting-http-500-httpcompileexception-error To debug more you can use solution provided in below link. https://www.linkedin.com/pulse/ax7-500-error-shashi-kant-yadav In my case the issue was related to the certificate expiration. To check the expired certificate on the server we can go to "Certificate Management Console" and see the certificates expiration date. To check this is power shell open "Windows PowerS

A reference to 'Dynamics.AX.XXXXX, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module.

The error "A reference to 'Dynamics.AX.Directory, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is required to compile this module." came on when i was building the project in visual studio. This error is thrown when the model is missing any reference which are needed to build the project. To update rectify this error we need to update the model. To do that go to "Dynamics 365 > Model Management > Update model parameter" A new window will open the model you want to update. Here i am selecting "Development" which i have created. Then click on next. On "Select referenced packages" select the missing packages which ones is throwing error. Here i have selected the "Directory" packages as they are the once throwing error. Select the packages. After selecting the packages click on "Next". And Click on "Finish". Rebuild the project and you are good to go.

D365 Month end and year end process

Period Closing Accounts Payable a.          Post invoices for all open/received purchase orders. b.          Post all pending invoices if received from Vendor. c.          Post and settle all payments. d.          Run Currency revaluation e.          Reconcile Vendor balance and trial balance for control accounts. f.           Set fiscal period on-hold for Vendor. Accounts Receivable a.          Post invoices for all open/delivered sales orders. b.          Post all pending free text invoices. c.          Post and settle all received payments. d.          Run Currency revaluation e.          Reconcile Vendor balance and trial balance for control accounts. f.           Set fiscal period on-hold for Customer. Cash and Bank a.          Perform Bank reconciliation b.          Set fiscal period on-hold for Bank. Procurement / Sales a.          Review and Close all open purchase/sales orders/Requisition if require. b.          Perform sort cl