Axapta 将第一个电子地址设为主地址
我想将联系人上插入的第一个电子地址(如电子邮件地址)设为主地址,插入地址时,第二个地址可能不会自动变为主地址 因此,我想修改表上的Axapta 将第一个电子地址设为主地址,axapta,dynamics-ax-2012,x++,Axapta,Dynamics Ax 2012,X++,我想将联系人上插入的第一个电子地址(如电子邮件地址)设为主地址,插入地址时,第二个地址可能不会自动变为主地址 因此,我想修改表上的insert方法: LogisticsElectronicAddress public void insert() { ttsbegin; if (!this.Location) { this.Location = LogisticsLocation::create('', false).RecId; }
insert
方法:
LogisticsElectronicAddress
public void insert()
{
ttsbegin;
if (!this.Location)
{
this.Location = LogisticsLocation::create('', false).RecId;
}
super();
this.updatePrimary(this.IsPrimary);
/* This is the modifications I made to check for an other primary address
if (!this.otherPrimaryExists())
{
this.IsPrimary = true;
}
*/
ttscommit;
this.invalidatePresenceInfo();
}
方法otherPrimaryExists()
包含:
/// <summary>
/// Checks whether primary record exists for the location.
/// </summary>
/// <returns>
/// true if another electronic address record is primary for the location; otherwise, false.
/// </returns>
public boolean otherPrimaryExists()
{
LogisticsElectronicAddress logisticsElectronicAddress;
select firstonly RecId from logisticsElectronicAddress
where logisticsElectronicAddress.Location == this.Location &&
logisticsElectronicAddress.Type == this.Type &&
logisticsElectronicAddress.IsPrimary == true &&
logisticsElectronicAddress.RecId != this.RecId;
return logisticsElectronicAddress.RecId != 0;
}
//
///检查该位置是否存在主记录。
///
///
///如果另一个电子地址记录是该位置的主地址,则为true;否则,错误。
///
公共布尔值otherPrimaryExists()
{
物流电子地址物流电子地址;
从logisticsElectronicAddress中选择firstonly RecId
其中logisticsElectronicAddress.Location==此.Location&&
logisticsElectronicAddress.Type==此.Type&&
logisticsElectronicAddress.IsPrimary==true&&
logisticsElectronicAddress.RecId!=this.RecId;
return logisticsElectronicAddress.RecId!=0;
}
问题是,所有电子地址都成为主要地址,当我关闭表单时,所有主要标记都被删除。如何解决此问题?这是因为您在执行插入后设置了
isPrimary=true
,并且没有调用后续更新
简单的解决方案是,只需将代码移到超级调用之上
LogisticsElectronicAddress
public void insert()
{
ttsbegin;
if (!this.Location)
{
this.Location = LogisticsLocation::create('', false).RecId;
}
/* This is the modifications I made to check for an other primary address
// Move this here
if (!this.otherPrimaryExists())
{
this.IsPrimary = true;
}
*/
super();
this.updatePrimary(this.IsPrimary);
ttscommit;
this.invalidatePresenceInfo();
}
这是因为您在已经执行了插入并且没有调用后续更新之后,正在设置
isPrimary=true
简单的解决方案是,只需将代码移到超级调用之上
LogisticsElectronicAddress
public void insert()
{
ttsbegin;
if (!this.Location)
{
this.Location = LogisticsLocation::create('', false).RecId;
}
/* This is the modifications I made to check for an other primary address
// Move this here
if (!this.otherPrimaryExists())
{
this.IsPrimary = true;
}
*/
super();
this.updatePrimary(this.IsPrimary);
ttscommit;
this.invalidatePresenceInfo();
}
修改
insert
方法如下:
public void insert()
{
;
ttsbegin;
if (!this.Location)
{
this.Location = LogisticsLocation::create('', false).RecId;
}
if (!this.otherPrimaryExists())
{
this.IsPrimary = true;
}
super();
this.updatePrimary(this.IsPrimary);
ttscommit;
this.invalidatePresenceInfo();
}
如果在调用
super
后设置字段值,此值将不会存储在数据库中。修改插入
方法,如下所示:
public void insert()
{
;
ttsbegin;
if (!this.Location)
{
this.Location = LogisticsLocation::create('', false).RecId;
}
if (!this.otherPrimaryExists())
{
this.IsPrimary = true;
}
super();
this.updatePrimary(this.IsPrimary);
ttscommit;
this.invalidatePresenceInfo();
}
如果在调用super
后设置字段值,则此值不会存储在数据库中