Remove certain property values onAfterVersion an Item

Hi, this one sounds like an easy to do task, but it´s somehow not. I want to reset certain ERP related properties after creating a new generation of a Part. My idea was to use a simple onAfterVersion Method for this task:
innnovator inn=this.getInnovator();

string partConfigId=this.getProperty("config_id");
string itemType=this.getType();

// Get newest version of this Part
Item newPart = this.newItem("Part","get");
newPart.setProperty("config_id", this.getProperty("config_id"));
newPart.setProperty("is_current","1");
newPart.setAttribute("select", "id");
newPart = newPart.apply();
if (newPart.isError())
{
    return inn.newError("Keine neue Revision gefunden: " + newPart.getErrorDetail() ); 
} 
string newId = newPart.getID(); // works!

// Edit newest version of this item
Item editPart = inn.getItemById("Part", newId);
editPart.setAction("edit");
editPart.setAttribute("doGetItem", "0");
editPart.setProperty("erp_is_matched","0");
editPart.removeProperty("erp_variant");
editPart = editPart.apply();
Unfortunately this code doesn´t update any value of the newest Part version. Even applySQL or grant of special permission doesn´t change anything. My only remaining idea is to customize related Methods like PE_CreateNewRevision and the transition handlers...again.. Is there some more general option available to change values after versioning an Item programatically? Best regards, Angela
Parents
  • Hi Angela, I had this issue a few months ago. It seems that after the OnAfterVersion event always a on***update event is fired. In this case it seems that this only contains few properties (anyhow: id). So maybe the following code snippet called by a onbeforeupdate event may help yo:
    string configId = this.getProperty("config_id");
    if(String.IsNullOrEmpty(configId))
    {
       // We are coming from change management, in case of 'normal' update configId isn't empty
       this.setProperty("erp_is_matched","0");
    } 
    
    I don't really understand why - but in my case it works. I hope this will help you. Best regards, Andreas
Reply
  • Hi Angela, I had this issue a few months ago. It seems that after the OnAfterVersion event always a on***update event is fired. In this case it seems that this only contains few properties (anyhow: id). So maybe the following code snippet called by a onbeforeupdate event may help yo:
    string configId = this.getProperty("config_id");
    if(String.IsNullOrEmpty(configId))
    {
       // We are coming from change management, in case of 'normal' update configId isn't empty
       this.setProperty("erp_is_matched","0");
    } 
    
    I don't really understand why - but in my case it works. I hope this will help you. Best regards, Andreas
Children
No Data