Add notes as attachment via custom code in X++.
In my current project requirement a simple note is required to be added via code in D365 Finance and Operations masters. This is achieved via below code requirements.
Solution:
Let me tell in simple pattern to be followed which can be used in any format.
Step1. Create a Runnable class in Visual Studio after creating a new project and attaching models with it.
Step2. Define the code.
class VendAccountDocument
{
? ? /// <summary>
? ? /// Runs the class with the specified arguments.
? ? /// </summary>
? ? /// <param name = "_args">The specified arguments.</param>
? ? public static void main(Args _args)
? ? {
? ? ? ? VendTable vendTable;
? ? ? ? DocuType docuType;
? ? ? ? DocuRef docuRef;
? ? ? ? vendTable = VendTable::find('104');
? ? ? ? docuType = DocuType::find('Note');
? ? ? ? if(!docuType||docuType.TypeGroup!=DocuTypeGroup::Note)
? ? ? ? {
? ? ? ? ? ? throw Error("Invalid document type");
? ? ? ? }
? ? ? ? docuRef.RefCompanyId = vendTable.DataAreaId;
? ? ? ? docuRef.RefTableId? ?= vendTable.TableId;
? ? ? ? docuRef.RefRecId? ? ?= vendTable.RecId;
? ? ? ? docuRef.TypeId? ? ? =? docuType.TypeId;
? ? ? ? docuRef.Name = 'Automatic note';
? ? ? ? docuRef.Notes = 'Automatic Notes';
? ? ? ? docuRef.insert();
? ? ? ? Info("Document note has been added successfully");
? ? }
}
Code Explanation:
Result of this code:
I wish this will help to take it further.