Updating Contact Person Information in Customer Contact Information Module in D365FO
Requirement:
My requirement is to get a Contact person's contact information from smmcontactperson form to the Custtable form in the Contact Information tab.
3. >. Customer Contact Information Tab
Develop procedure:
>. Take an extension of
logisticselectronicsaddress table and add contacted
>. After adding the field then
go to logisticscontactinfogrid form and drag that contacted field into grid.
>. It will show that field in the customer information tab.
[ExtensionOf(formdatasourcestr(LogisticsContactInfoGrid,LogisticsElectronicAddress))]
internal final class DAXLogisticsElectronicAddress_Extension
{
public boolean validateWrite()
{
boolean ret;
ContactPerson contactPerson;
DirPartyTable dirPartyTable , dirPartyTableLoc;
CustTable custTable , custTableLoc;
LogisticsElectronicAddress logisticsElectronicaddress , logistcsElectronicAddressloc,electronicaddress,logistcscheck;
LogisticsLocation logisticslocation , logisticslocationloc;
DirPartyLocation dirPartyLocation , dirPartylocationloc;
LogisticsLocationRole locationRole;
Map locationRoleMap;
container locationRoleCon;
FormDataSource fds = this.formRun().dataSource();
formRun callerformrun = this.formRun().args().caller();
ContactPerson contactPersonLoc = callerformrun.dataSource().cursor();
logisticsElectronicAddress = this.cursor();
ret = next validateWrite();
if(callerformrun.name() == formStr("smmcontactperson") && logisticsElectronicAddress.isNewRecord()
|| logisticsElectronicAddress.isFieldModified(fieldNum(logisticsElectronicAddress,Locator))
||logisticsElectronicAddress.isFieldModified(fieldNum(logisticsElectronicAddress,Description ))
||logisticsElectronicAddress.isFieldModified(fieldNum(logisticsElectronicAddress,LocatorExtension ))
||logisticsElectronicAddress.isFieldModified(fieldNum(logisticsElectronicAddress,IsPrimary )) )
{
select * from contactPerson where contactPerson.ContactPersonId == contactPersonLoc.ContactPersonId ;
select * from custTable where custTable.party == contactPerson.ContactForParty;
select *from dirPartyTable where dirPartyTable.RECID == contactPerson.PARTY ;
{
select forupdate electronicaddress
where electronicaddress.ContactId == contactPerson.ContactPersonId
&& electronicaddress.Type == logisticsElectronicAddress.Type
&& electronicaddress.AddressId == logisticsElectronicAddress.ElectronicAddressId
join dirPartylocationloc
where electronicaddress.Location == dirPartylocationloc.Location
join dirPartyTableLoc
where dirPartyTableLoc.RecId == dirPartylocationloc.party
join custTableLoc
where custTableLoc.Party == dirPartyTableLoc.RecId
&& custTableLoc.AccountNum ==custtable.AccountNum;
if(!electronicaddress)
{
locationRoleMap = new Map(Types::Int64, Types::String);
locationRole = LogisticsLocationRole::findByName('Business');
if (locationRole)
{
locationRoleMap.insert(locationRole.RecId, locationRole.description());
locationRoleCon = map2Con(locationRoleMap);
ttsBegin;
logistcsElectronicAddressloc.Type = logisticsElectronicAddress.Type;
logistcsElectronicAddressloc.Locator = logisticsElectronicAddress.locator;
logistcsElectronicAddressloc.Location = DirPartyLocation::findOrCreate(custTable.Party, 0).Location;
logistcsElectronicAddressloc = LogisticsElectronicAddress::findOrCreate(logistcsElectronicAddressloc);
logistcsElectronicAddressloc = LogisticsElectronicAddress::findRecId(logistcsElectronicAddressloc.RecId, true);
logistcsElectronicAddressloc.Description = logisticsElectronicAddress.Description ;
logistcsElectronicAddressloc.IsPrimary = logisticsElectronicAddress.IsPrimary;
logistcsElectronicAddressloc.ContactId = contactPerson.ContactPersonId;
logistcsElectronicAddressloc.AddressId = logisticsElectronicAddress.ElectronicAddressId;
logistcsElectronicAddressloc.LocatorExtension = logisticsElectronicAddress.LocatorExtension;
logistcsElectronicAddressloc.update();
LogisticsEntityLocationRoleMap::createEntityLocationRoles(tableNum(LogisticsElectronicAddressRole), logistcsElectronicAddressloc.RecId, conPeek(locationRoleCon, 1), true);
ttsCommit;
}
}
else
{
ttsbegin;
electronicaddress.Description = logisticsElectronicAddress.Description;
electronicaddress.Locator = logisticsElectronicAddress.Locator;
electronicaddress.LocatorExtension = logisticsElectronicAddress.LocatorExtension;
electronicaddress.IsPrimary = logisticsElectronicAddress.IsPrimary;
electronicaddress.update();
ttscommit;
}
}
}
return ret;
}
public void delete()
{
FormRun formRun = this.formRun().args().caller();
FormDataSource Fds= formrun.dataSource();
DirPartyTable dirPartyTable , dirPartyTableLoc;
CustTable custTable , custTableLoc;
LogisticsElectronicAddress logisticsElectronicaddress , logistcsElectronicAddressloc,electronicaddress;
LogisticsLocation logisticslocation , logisticslocationloc;
DirPartyLocation dirPartyLocation , dirPartylocationloc;
if(formRun.name() == formStr("smmcontactperson") )
{
ContactPerson contactperson = fds.cursor();
logisticsElectronicAddress = this.cursor();
select * from custtable
where custtable.AccountNum == contactperson.CustAccount;
ttsbegin;
select forupdate electronicaddress
where electronicaddress.ContactId == contactPerson.ContactPersonId
&& electronicaddress.Type == logisticsElectronicAddress.Type
&& electronicaddress.AddressId == logisticsElectronicAddress.ElectronicAddressId
exists join dirPartylocationloc
where electronicaddress.Location == dirPartylocationloc.Location
join dirPartyTableLoc
where dirPartyTableLoc.RecId == dirPartylocationloc.party
join custTableLoc
where custTableLoc.Party == dirPartyTableLoc.RecId
&& custTableLoc.AccountNum ==custtable.AccountNum ;
if (electronicaddress)
{
electronicaddress.delete();
}
ttscommit;
}
next delete();
}
}
extension of DirPartyQuickCreateForm :-
[ExtensionOf(formStr(DirPartyQuickCreateForm))]
internal final class DAXDirPartyQuickCreateForm_Extension
{
public void closeOk()
{
ContactPerson contactPerson;
DirPartyTable dirPartyTable ;
CustTable custTable ;
LogisticsElectronicAddress logisticsElectronicaddress , logistcsElectronicAddressloc;
LogisticsLocation logisticslocation , logisticslocationloc;
DirPartyLocation dirPartyLocation;
LogisticsLocationRole locationRole;
Map locationRoleMap;
container locationRoleCon;
next closeOk();
FormRun formrun = this.dataSource().formRun();
Common common = this.dataSource().cursor();
ContactPerson contactPersonloc = common;
formRun callerformrun = formRun.args().caller();
logisticsElectronicaddress = formrun.dataSource("LogisticsElectronicAddressEmail").cursor();
if(callerformrun.name()== formStr("smmcontactperson"))
{
custTable = CustTable::find(contactPersonloc.CustAccount);
while select contactPerson where contactPerson.ContactPersonId == contactPersonLoc.ContactPersonId
join dirPartyTable where dirPartyTable.RECID == contactPerson.PARTY
join dirPartyLocation where dirPartyTable.RecId == dirPartyLocation.Party
join logisticsElectronicaddress where dirPartyLocation.Location == logisticsElectronicaddress.Location
{
locationRoleMap = new Map(Types::Int64, Types::String);
locationRole = LogisticsLocationRole::findByName('Business');
if (locationRole)
{
locationRoleMap.insert(locationRole.RecId, locationRole.description());
locationRoleCon = map2Con(locationRoleMap);
ttsBegin;
logistcsElectronicAddressloc.Type = logisticsElectronicAddress.Type;
logistcsElectronicAddressloc.Locator = logisticsElectronicAddress.locator;
logistcsElectronicAddressloc.Location = DirPartyLocation::findOrCreate(custTable.Party, 0).Location;
logistcsElectronicAddressloc = LogisticsElectronicAddress::findOrCreate(logistcsElectronicAddressloc);
logistcsElectronicAddressloc = LogisticsElectronicAddress::findRecId(logistcsElectronicAddressloc.RecId, true);
logistcsElectronicAddressloc.Description = logisticsElectronicAddress.Description ;
logistcsElectronicAddressloc.IsPrimary = logisticsElectronicAddress.IsPrimary;
logistcsElectronicAddressloc.ContactId = contactPerson.ContactPersonId;
logistcsElectronicAddressloc.AddressId = logisticsElectronicAddress.ElectronicAddressId;
logistcsElectronicAddressloc.LocatorExtension = logisticsElectronicAddress.LocatorExtension;
logistcsElectronicAddressloc.update();
LogisticsEntityLocationRoleMap::createEntityLocationRoles(tableNum(LogisticsElectronicAddressRole), logistcsElectronicAddressloc.RecId, conPeek(locationRoleCon, 1), true);
ttsCommit;
}
}
}
}
}
Direct delete the contact Id:-
datasource extension:-
[ExtensionOf(formDataSourceStr(smmContactPerson,ContactPerson))]
internal final class DAXSmmContactPerson_Extension
{
public void delete()
{
DirPartylocation dirPartylocation;
DirPartyTable dirPartyTable;
LogisticsElectronicAddress logisticsElectronicAddress;
ContactPerson contactPerson;
CustTable custTable;
FormRun formrun = this.formRun();
ContactPerson contactPersonLoc= formRun.dataSource().cursor();
FormRun Callerform = formRun.args().caller();
str value;
value = contactPersonLoc.CustAccount;
str value1;
value1 = contactPersonLoc.ContactPersonId;
next delete();
if(callerform.name()== formStr("CustTable"))
{
// CustTable custTable = CustTable::find(contactPersonloc.CustAccount);
while select custTable where custTable.AccountNum == value
join dirPartyTable where dirPartyTable.RECID == custTable.PARTY
join dirPartyLocation where dirPartyTable.RecId == dirPartyLocation.Party
join logisticsElectronicaddress where dirPartyLocation.Location == logisticsElectronicaddress.Location
&& logisticsElectronicaddress.ContactId == value1
{
if(logisticsElectronicaddress)
{
ttsbegin;
logisticsElectronicaddress.selectforUpdate(true);
logisticsElectronicaddress.delete();
ttscommit;
}
}
}
}
}
------------------------
Output:-
No comments:
Post a Comment