2017-03-16 61 views
0

我想要在联系人(例如电子邮件地址)上插入第一个电子地址作为主要地址,当插入地址时,第二个地址可能不会成为主要自动地址。创建第一个电子地址主

Herefore我想修改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; 
} 

的问题是,所有的电子地址正在成为主要的,而当我关闭表格中的所有主标记都将被删除。如何解决这个问题呢?

回答

3

这是因为您在已经执行插入并且没有更新被调用之后设置了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(); 
} 
3

修改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后场值,这个值将不会被存储在数据库中。

相关问题