Calculate Stock on Order Values

Hi Everyone

I have been struggling with creating a server side method for the following scenario I have 2 Item Types and a Relationship between. I would like the value of the Relationship property _order_qty added to the value of the Child relationship property _stock_on_order when creating a  POR.

ItemType 1 - POR

Relationship - POR_Part (Property = _order_qty)

ItemType 2 - Part (Property = _stock_on_order)

So basically get the current _stock_on_order then _stock_on_order + _order_qty and then rewrite the _stock_on_order value on the Part ItemType. 

I have a separate script that will subtract the received stock quantity from _stock_on_order. 

Thanks! 

Parents
  • Hi Wian,

    there are multiple approaches available. What is your trigger, e.g. an onAfteAdd/Update Event on POR_Part? Then you simply could use an edit query on the related_id. As you want to edit your Part, you may have to use an SQL based approach or at least grant permission.

    Is your POR_Part and Part combination unique? 

Reply
  • Hi Wian,

    there are multiple approaches available. What is your trigger, e.g. an onAfteAdd/Update Event on POR_Part? Then you simply could use an edit query on the related_id. As you want to edit your Part, you may have to use an SQL based approach or at least grant permission.

    Is your POR_Part and Part combination unique? 

Children
  • Hi Angela

    I think onAfterUpdate would work the best. As you save the POR it then writes in the value. 

    We can have multiple POR_Part and Part combinations currently.

  • Some standard code like this should already to it. I would use it for onAfterAdd and Update from your relationship ItemType:

    // Grant 'Aras PLM' permissions
    Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");
    bool PermissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(plmIdentity);

    try
    {

    string myId = this.getProperty("related_id");
    Item editItem = inn.getItemById("Part", myId);
    editItem.setAction("edit");
    editItem.setAttribute("doGetItem", "0");
    editItem.setProperty("myproperty","newvalueforproperty");
    editItem = editItem.apply();
    if (editItem.isError())
    {
         return inn.newError("An error occured: " + editItem .getErrorDetail() );
    }
    return editItem;
    }
    finally
    {
    // Revoke 'Aras PLM' permissions
    if (PermissionWasSet)
    Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
    }

  • Thanks so much Angela I will give it a go this afternoon to see if I can make this work :) 

  • Hi Angela

    Thanks so much for the guidance, I got this working, just for interest here is my 'edits" to your code below.

    Innovator myInn = this.getInnovator();
    // Grant 'Aras PLM' permissions
    Aras.Server.Security.Identity plmIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");
    bool PermissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(plmIdentity);

    try
    {
    string myId = this.getProperty("related_id","");
    string orderqty_string = this.getProperty("_order_qty","");
    int orderqty;
    int.TryParse(orderqty_string,out orderqty);
    Item editItem = myInn.getItemById("Part", myId);
    editItem.setAction("edit");
    editItem.setAttribute("doGetItem", "0");
    string stockorder_qty = editItem.getProperty("_stock_on_order","");
    int stockorder;
    int.TryParse(stockorder_qty,out stockorder);
    int sum = orderqty + stockorder;
    editItem.setProperty("_stock_on_order",sum.ToString());
    editItem = editItem.apply();
    if (editItem.isError())
    {
    return myInn.newError("An error occured: " + editItem .getErrorDetail() );
    }
    return editItem;
    }
    finally
    {
    // Revoke 'Aras PLM' permissions
    if (PermissionWasSet)
    Aras.Server.Security.Permissions.RevokeIdentity(plmIdentity);
    }

  • Happy to hear you were able to get this code working! Not sure if you really need the grant permission part, but when you do "Part" editing, it´s normally necessary.