Get beforeupdate Relationships value from parent item

オフライン

there is a item name -Part

and it has relation -Part_relation

there are a date field and name field in Part_relation 

when user update , I want to check the field'value Cannot be earlier than Today

When encountering an error, I will return inn.newError(name + date+"  error")

it is my question

When encountering multiple errors, how can I get Part_relation 's information (on the view) show on Error message

in Part's beforeUpdate event?

I think "this.getRelationships();" works, but I failed after testing.

----------------------------------------------------

string log ="";
Innovator inn = this.getInnovator();

Item rootitem = inn.getItemById(this.getType(), this.getID());

//on the view's all relationship
Item thisrela = this.getRelationships();

string today = DateTime.Now.ToString("yyyy/MM/dd");
DateTime nowdate = Convert.ToDateTime(today);


for(int a=0 ; a<thisrela.getItemCount(); a++){
       Item tR = thisrela.getItemByIndex(a);----> it can't run
       //on view's date
  string updateday = Convert.ToDateTime(tR.getProperty("ts_complete_date")).ToString("yyyy/MM/dd");

  DateTime update = Convert.ToDateTime(updateday);
  if(DateTime.Compare(nowdate,update)>0){
   log += "tR.getProperty("name")+update+" Error.";
  }  
}


if(log!=""){
    return inn.newError(log);
}

Parents
  • Hi Zachary

    Try below code and let me know if it works. You can use fetchRelationships of particular relationship name (here I used Part BOM). (Assuming that the property ts_complete_date and name is on Relationship Item type)

    string log = string.Empty;
    Innovator inn = this.getInnovator();
    string today = DateTime.Now.ToString("yyyy/MM/dd");
    DateTime nowdate = Convert.ToDateTime(today);

    this.fetchRelationships("Part BOM");
    Item thisrela= this.getRelationships("Part BOM");
    for(int a = 0 ; a < thisrela.getItemCount(); a++)
    {
        Item tR = thisrela.getItemByIndex(a);
        string updateday = Convert.ToDateTime(tR.getProperty("ts_complete_date")).ToString("yyyy/MM/dd");
        DateTime update = Convert.ToDateTime(updateday);
        if(DateTime.Compare(nowdate,update)>0)
        {
            log += tR.getProperty("name") +update+ "Error.";
        }
    }
    if(!String.IsNullOrEmpty(log))
    {
        return inn.newError(log);
    }
    return this;
    If the property ts_complete_date and name is on Part Item type then use below line after Item thisrela= this.getRelationships("Part BOM"); to get the related item property.
    Item relItem = tR.getRelatedItem();
    You can use like relItem.getProperty("ts_complete_date") to get the values.
    Thanks
    Gopikrishnan R
Reply
  • Hi Zachary

    Try below code and let me know if it works. You can use fetchRelationships of particular relationship name (here I used Part BOM). (Assuming that the property ts_complete_date and name is on Relationship Item type)

    string log = string.Empty;
    Innovator inn = this.getInnovator();
    string today = DateTime.Now.ToString("yyyy/MM/dd");
    DateTime nowdate = Convert.ToDateTime(today);

    this.fetchRelationships("Part BOM");
    Item thisrela= this.getRelationships("Part BOM");
    for(int a = 0 ; a < thisrela.getItemCount(); a++)
    {
        Item tR = thisrela.getItemByIndex(a);
        string updateday = Convert.ToDateTime(tR.getProperty("ts_complete_date")).ToString("yyyy/MM/dd");
        DateTime update = Convert.ToDateTime(updateday);
        if(DateTime.Compare(nowdate,update)>0)
        {
            log += tR.getProperty("name") +update+ "Error.";
        }
    }
    if(!String.IsNullOrEmpty(log))
    {
        return inn.newError(log);
    }
    return this;
    If the property ts_complete_date and name is on Part Item type then use below line after Item thisrela= this.getRelationships("Part BOM"); to get the related item property.
    Item relItem = tR.getRelatedItem();
    You can use like relItem.getProperty("ts_complete_date") to get the values.
    Thanks
    Gopikrishnan R
Children