Updating purpose (roles) for contact information (email)

Hi,

i want to update email of a customer with new roles (purpose - invoice) its blank currently, my code is below:

this issue is i get two addresses, one with purpose invoice, one without it, how do i update correctly ? i do this over customers v3 entity

DirParty                   dirParty;
DirPartyContactInfoView    dirPartyContactInfoView;
container                  roles;

ttsbegin;
dirParty = DirParty::constructFromPartyRecId(DirPartyTable::findByNum(this.PartyNumber).RecId);

roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];
 
dirPartyContactInfoView.Type       = LogisticsElectronicAddressMethodType::Email;
dirPartyContactInfoView.Locator    = this.PrimaryContactEmail;
dirPartyContactInfoView.IsPrimary  = NoYes::Yes;
dirPartyContactInfoView.Party      = DirPartyTable::findByNum(this.PartyNumber).RecId;		
dirPartyContactInfoView.LocationId = this.ElectronicLocationId;
dirPartyContactInfoView.Location   = DirPartyLocation::findOrCreate(dirPartyContactInfoView.Party, 0).Location;

dirParty.createOrUpdateContactInfo(dirPartyContactInfoView, roles);
ttscommit;

I did it this way:

container                  roles;
logisticsElectronicAddress logisticsElectronicAddress;

roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice).RecId];

ttsbegin;

logisticsElectronicAddress.clear();
logisticsElectronicAddress.Type =  LogisticsElectronicAddressMethodType::Email;
logisticsElectronicAddress.Locator = this.PrimaryContactEmail;
logisticsElectronicAddress.Location = DirPartyLocation::findOrCreate(DirPartyTable::findByNum(this.PartyNumber).RecId, 0).Location;

logisticsElectronicAddress = LogisticsElectronicAddress::findElectronicAddress(logisticsElectronicAddress);

if(logisticsElectronicAddress)
{
    LogisticsElectronicAddressRole::createLocationRoles(logisticsElectronicAddress.RecId, roles, true);
}

ttscommit;

Its working now?

What is Question here? I didn’t understood yet…So far code looks good to me.

seems like he fixed it on his own!