Tuesday, August 13, 2019

How to add an Entity in Data Project through code (X++)

         DMFDefinitionGroupEntity   addEntity;

        if (DMFQuickImportExportFormHelper::validateEntity(_entityName, _sourceName, DMFOperationType::Export))
        {
            ttsbegin;
            addEntity.clear();
            addEntity.initValue();
            addEntity.DefaultRefreshType = DMFRefreshType::IncrementalPush;
            addEntity.DefinitionGroup = _definitionGroup;
            addEntity.Entity = _entityName;
            addEntity.EntityXMLName = _targetEntity;
            addEntity.SkipStaging = NoYes::Yes;
            addEntity.source = _sourceName;
            addEntity.validationStatus = NoYesError::Yes;
            addEntity.ExecutionUnit = NoYes::Yes;
            addEntity.LevelInExecutionUnit = NoYes::Yes;
            addEntity.insert();

            //Generate mapping
            DMFXmlGeneration::generateMappingV2(addEntity);
            ttscommit;
                       
           
        }

Variables -

  1. _entityName - Name of the Entity
  2. _SourceName - Source Data Format (like BYOD, Excel)
  3. _definitionGroup - Definition Group Name (or Data Project Name)

#DataEntities #X++ #D365F&O #DMF