Microsoft Dynamics 365 Blog

To import employees via Excel use a concept similar to the import of customers and vendors but add additional tricks to get the Name and Search name fields from the DirPartyTable populated.  (If you are unfamiliar with importing customers and vendors see KB article #960729.)

When defining your Excel import choose to import into the EmplTable and keep some fields in the Excel spreadsheet for the EmplTable that you don’t need for Employee record.  We’ll use those fields to store away the first, last and name fields for the DirPartyTable so that you have the name information available when the import runs.  In the example code below I used the Education, National ID number and Attention information fields in the EmplTable. 

In the conversion code on the Excel import have the code update the DirPartyTable with the values in the Education, National ID number and Attention information fields.  After you’ve set the fields in the DirPartyTable set the EmplTable fields to nothing so they don’t get set in the EmplTable.  The code belows works for the fields I used:

str dirId;

DirPartyTable dirPartyTable

;

 

// Check if not associated to Party

if (!emplTable.PartyId || emplTable.PartyId == “”)

{

// Create a Party entry for customer

dirId = DirParty::createPartyFromCommon(emplTable).PartyId;

emplTable.PartyId = dirId;

//Update the name fields on the DirPartyTable 

while select forupdate dirPartyTable where dirPartyTable.PartyId == emplTable.PartyId

{

dirPartyTable.FirstName = emplTable.Training;

dirPartyTable.LastName = emplTable.EmplIdentNumber;

dirPartyTable.Name = emplTable.ReqAttention;

dirPartyTable.NameAlias = emplTable.ReqAttention;

dirPartyTable.update();

}

//Set the values in the EmplTable back to nothing

 

emplTable.Training = “”;

emplTable.EmplIdentNumber = “”;

emplTable.ReqAttention = “”;

 

}

else

{

DirParty::updatePartyFromCommonInsert(emplTable.PartyId,EmplTable);

}

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!