Thursday, January 16, 2020

Catch weight item in D365

Introduction

You could have a scenario particularly in manufacturing industry where a finished good or a product can vary in size, weight or both. In this case, you would have two units of measures for these sort of products (i.e. Catch weight unit and Inventory Unit.). Catch weight unit is the unit in which inventory transactions are performed, for example sold, received, transferred, picked, and shipped etc. The inventory unit is the unit of measure when the product is weighed and invoiced. .  The nominal quantity is the conversion between the catch weight unit and the inventory unit. These items are called catch weight items

Table Schema 

There are many important tables used in product information and management module. Few of the important tables and classes are listed in this blog .
Except all these important tables such as EcoResProduct, InventTable we do have a separate table for catch weights items that is PDSCatchWeightItem.

How do we identify the Released Item marked as catch weight item?

You can search a release item that is also a catch weight item adding a new field named, “CW product” and filter the grid with marked checked.


Or using the database you can use the SQL query
SELECT PDSCATCHWEIGHTITEM.* FROM PDSCATCHWEIGHTITEM
JOIN INVENTTABLE
ON INVENTTABLE.ITEMID = PDSCATCHWEIGHTITEM.ITEMID
AND PDSCATCHWEIGHTITEM.DATAAREAID = 'usmf'

How to create a catch weight item in D365?

Since the catch weight item was introduced in AX in version 2012 and all the steps that are almost same as mentioned in the blog - Creating a Product using the Catch Weight functionality in Microsoft Dynamics AX 2012. Also one thing you have to make sure transfer the appropriate inventory quantity to newly created catch weight item and also make sure to assign the important accounts to item group of the item. Otherwise it will block you using that item in sales and purchase orders. I hope this blog post will give you a brief view of catch weight item, let me know your feedback and queries via comments.



References:

Catch weight functionality a critical requirement for food manufacturing.

Friday, January 10, 2020

How to send that attachments as an email in D365

Normally in D365, there is a common table where your attachments are saved that is DocuRef, and it also stores the reference of table in field "RefTableId" field. Suppose we want to retrieve all the attachments specific to a table. We can simple achieve this using the RefTableId. Next important this is using the buffer of DocuRef table, we have multiple available options using this buffer. for example we can simple retrieve the container using the function as below:

 container _data = DocumentManagement::getAttachmentAsContainer(docRef)"

This container can further be passed on to method as provided below

public static void sendPDFEamilAttachment( SysEmailId      _emailId,
        LanguageId      _language,
        SysEmailAddress             _emailAddr,
        Map             _mappings,container _data,str _fileName)
    {
        SysEmailItemId                   nextEmailItemId;
        SysEmailTable                    sysEmailTable;
        SysEmailMessageTable             sysEmailMessageTable;
        SysEmailContents                 sysEmailContents;
        SysOutgoingEmailTable            outgoingEmailTable;
        SysOutgoingEmailData             outgoingEmailData;
        Filename filename, FileExtension;
      
        FileExtension=".pdf";
       
        select sysEmailTable
               join    sysEmailMessageTable
                where sysEmailMessageTable.EmailId==sysEmailTable.EmailId
                    && sysEmailMessageTable.EmailId== _emailId
                    && sysEmailMessageTable.LanguageId==_language;
       
        if(sysEmailTable.RecId>0)
        {
            sysEmailContents=SysEmailMessage::stringExpand(sysEmailMessageTable.Mail, _mappings);
            nextEmailItemId = EventInbox::nextEventId();
      
            filename =strFmt("%1_%2.pdf",nextEmailItemId,_fileName);
    
    
            outgoingEmailTable.clear();
            outgoingEmailTable.Origin=sysEmailTable.Description;
            outgoingEmailTable.EmailItemId = nextEmailItemId;
            outgoingEmailTable.IsSystemEmail = NoYes::Yes;
            outgoingEmailTable.Sender = sysEmailTable.SenderAddr;
            outgoingEmailTable.SenderName = sysEmailTable.SenderName;
            outgoingEmailTable.Recipient = _emailAddr;
            outgoingEmailTable.Subject =SysEmailMessage::stringExpand(sysEmailMessageTable.Subject, _mappings);
            outgoingEmailTable.Priority = eMailPriority::High;
            outgoingEmailTable.WithRetries = NoYes::NO;
            outgoingEmailTable.RetryNum = 0;
            outgoingEmailTable.UserId = curUserId();
            outgoingEmailTable.Status = SysEmailStatus::Unsent;
            outgoingEmailTable.Message =  sysEmailContents;
            outgoingEmailTable.LatestStatusChangeDateTime =DateTimeUtil::getSystemDateTime();
            outgoingEmailTable.TemplateId= _emailId;
            outgoingEmailTable.insert();


            if(conLen(_data)>0)
            {
                outgoingEmailData.clear();

                outgoingEmailData.EmailItemId = nextEmailItemId;
                outgoingEmailData.DataId = 1;
                outgoingEmailData.EmailDataType = SysEmailDataType::Attachment;
                outgoingEmailData.Data = _data;
                outgoingEmailData.FileName = filename;
                outgoingEmailData.FileExtension =FileExtension;

                outgoingEmailData.insert();
            }
        }
    }

}