Data Management Project Using X++
Using the following code, you can import the file and execute the project using your x++ code.
In the code, I am making the file on runtime and uploading the file into temp storage for the demo purpose
but you can use the file uploader as per your requirement.
Code
class AD_Test
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
FileUploadTemporaryStorageStrategy fileUploadStrategyInstance;
DMFDefinitionGroupEntity definitionGroupEntityBuffer;
DMFEntity dmfEntitybuffer;
FileUploadTemporaryStorageResult result;
SysDictClass uploadStrategyDictClassInstance;
str entityName = 'VendVendorGroupEntity';
System.IO.StreamWriter swriter;
System.IO.MemoryStream fileStream;
DMFExecutionId executionId;
#File
fileStream = new System.IO.MemoryStream();
swriter = new System.IO.StreamWriter(fileStream);
swriter.WriteLine("VENDORGROUPID,DESCRIPTION");
swriter.WriteLine(strFmt("%1,%2",'Ex-VendGroup','Example Vendor group'));
swriter.Flush();
uploadStrategyDictClassInstance = new SysDictClass(className2Id('FileUploadTemporaryStorageStrategy'));
fileUploadStrategyInstance = uploadStrategyDictClassInstance.makeObject() as FileUploadTemporaryStorageStrategy;
result = fileUploadStrategyInstance.uploadFile(fileStream, 'VendorsGroups.csv');
fileStream.Dispose();
CodeAccessPermission::revertAssert();
executionId = DMFUtil::setupNewExecution('ImportVendorGroup');
select firstonly Entity from definitionGroupEntityBuffer exists join dmfEntitybuffer
where definitionGroupEntityBuffer.DefinitionGroup == 'ImportVendorGroup' &&
dmfEntitybuffer.EntityName == definitionGroupEntityBuffer.Entity &&
dmfEntitybuffer.TargetEntity == entityName ;
DMFDefinitionGroupExecution executionBuffer = DMFDefinitionGroupExecution::find('ImportVendorGroup', definitionGroupEntityBuffer.Entity, executionId, true);
ttsbegin;
executionBuffer.FilePath = result.getFileId();
executionBuffer.IsTransformed = NoYes::Yes;
executionBuffer.update();
ttscommit;
DMFQuickImportExport::doPGImport('ImportVendorGroup', executionId, true);
}
}