How to implement server event that calculates a part's permission on update?

Hi, I want to add a server event to the Part ItemType that updates the Part's Permission based on some of the Part's properties. I.e. when the server event method detects that one or more of those properties are updated, the permission should be automatically updated by the method. Currently, I have added a method that triggers on the event  onBeforeUpdate:  However, when I vote to start work on an ECO where a part is set to the action Revise, I get the following error when I add a permission in my server method:  When I press the Complete button (before the error message on the image above appears), the following item is submitted to the method:
  <Item type="Part" action="edit" id="50B48766A923456ABE4FE28A74 157D09" doGetItem="0" version="0">
    <production_state>Preliminary</production_state>
  </Item>
Based on the (custom) production_state property, I calculate a new permission in the method, and I add it to the Item object before returning it from the server method. The result looks as follows:
  <Item type="Part" action="edit" id="50B48766A923456ABE4FE28A74 157D09" doGetItem="0" version="0">
    <production_state>Preliminary</production_state>
    <permission_id keyed_name="Permission" type="Permission">82F4810F7FC641339A2B667BA8EF0596</permission_id>
  </Item>
The essential things in my method are:
Item item = this;
Item newPermisson = GetNewPermission();
string newPermissionId = newPermission.getID();
item.setProperty("permission_id", newPermissionId);
item.setPropertyAttribute("permission_id", "keyed_name", "Permission");
item.setPropertyAttribute("permission_id", "type", "Permission");
return item;
When I set the permission property, I get the error as shown earlier. However, if I comment these lines out, it stops to throw the error message, so it's definitely something wrong in how I specify the new permission. How would you go about to update the permission for a Part when it is updated? Furthermore, how do I also make it so that my method is called when the Part is promoted to another state in its life cycle? When a Part changes state in its life cycle, its state and permission properties are updated, but that does apparently not count as an update on the Part type, which means that onBeforeUpdate is never called. What's the proper way to implement this?
Parents
  • Looked at the example, but I cannot get it to work. I created a new method to have a minimal example: Item newPermission = this.newItem("Permission", "get"); newPermission.setProperty("name", "Customer"); newPermission.apply(); this.setPropertyItem("permission_id", newPermission); File.AppendAllText("C:\\ArasLogs\\test.txt", this.dom.OuterXml); return this; It's added to the Part type. However, when I edit it and save a part, it still has its permission New Part. When it should be changed to the permission "Customer", as written in my server event. And in server event, I also write to file whenever it is executed, which it does when I save the part. So it's definitely being executed. It is being run twice, with these item outputs: <Item type="Part" typeId="4F1AC04A2B484F3ABA4E20DB63808A88" id="8821D59BCEC540978D2F246A5AD409C0" loadedPartialy="0" isDirty="1" LastModifiedOn="1512374887622" action="update" doGetItem="1"> <config_id keyed_name="TT" type="Part">5F7C0850DF1F4A84B6E03C7B85EFC074</config_id> <created_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id> <created_on>2017-12-04T02:49:42</created_on> <current_state keyed_name="Preliminary" type="Life Cycle State" name="Preliminary">72A2322564FE4193933CFB5339487A06</current_state> <generation>5</generation> <id keyed_name="TT" type="Part">8821D59BCEC540978D2F246A5AD409C0</id> <is_current>1</is_current> <is_released>0</is_released> <keyed_name>TT</keyed_name> <locked_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</locked_by_id> <major_rev>C</major_rev> <make_buy>Make</make_buy> <modified_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</modified_by_id> <modified_on>2017-12-04T03:03:28</modified_on> <name>TT123</name> <new_version>0</new_version> <not_lockable>0</not_lockable> <state>Preliminary</state> <unit>EA</unit> <item_number>TT</item_number> <itemtype>4F1AC04A2B484F3ABA4E20DB63808A88</itemtype> <permission_id> <Item isNew="1" isTemp="1" type="Permission" action="get"> <name>Customer</name> </Item> </permission_id> </Item> <Item type="Part" typeId="4F1AC04A2B484F3ABA4E20DB63808A88" id="C919C3C8CAA3405680A35EFBC0B27595" loadedPartialy="0" isDirty="1" LastModifiedOn="1512374887622" action="version" doGetItem="1" oldId="8821D59BCEC540978D2F246A5AD409C0"> <config_id keyed_name="TT" type="Part">5F7C0850DF1F4A84B6E03C7B85EFC074</config_id> <created_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id> <created_on>2017-12-04T02:49:42</created_on> <current_state keyed_name="Preliminary" type="Life Cycle State" name="Preliminary">72A2322564FE4193933CFB5339487A06</current_state> <generation>5</generation> <id keyed_name="TT" type="Part">8821D59BCEC540978D2F246A5AD409C0</id> <is_current>1</is_current> <is_released>0</is_released> <keyed_name>TT</keyed_name> <locked_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</locked_by_id> <major_rev>C</major_rev> <make_buy>Make</make_buy> <modified_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</modified_by_id> <modified_on>2017-12-04T03:03:28</modified_on> <name>TT123</name> <new_version>1</new_version> <not_lockable>0</not_lockable> <state>Preliminary</state> <unit>EA</unit> <item_number>TT</item_number> <itemtype>4F1AC04A2B484F3ABA4E20DB63808A88</itemtype> <permission_id> <Item isNew="1" isTemp="1" type="Permission" action="get"> <name>Customer</name> </Item> </permission_id> </Item> Why isn't this working?
Reply
  • Looked at the example, but I cannot get it to work. I created a new method to have a minimal example: Item newPermission = this.newItem("Permission", "get"); newPermission.setProperty("name", "Customer"); newPermission.apply(); this.setPropertyItem("permission_id", newPermission); File.AppendAllText("C:\\ArasLogs\\test.txt", this.dom.OuterXml); return this; It's added to the Part type. However, when I edit it and save a part, it still has its permission New Part. When it should be changed to the permission "Customer", as written in my server event. And in server event, I also write to file whenever it is executed, which it does when I save the part. So it's definitely being executed. It is being run twice, with these item outputs: <Item type="Part" typeId="4F1AC04A2B484F3ABA4E20DB63808A88" id="8821D59BCEC540978D2F246A5AD409C0" loadedPartialy="0" isDirty="1" LastModifiedOn="1512374887622" action="update" doGetItem="1"> <config_id keyed_name="TT" type="Part">5F7C0850DF1F4A84B6E03C7B85EFC074</config_id> <created_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id> <created_on>2017-12-04T02:49:42</created_on> <current_state keyed_name="Preliminary" type="Life Cycle State" name="Preliminary">72A2322564FE4193933CFB5339487A06</current_state> <generation>5</generation> <id keyed_name="TT" type="Part">8821D59BCEC540978D2F246A5AD409C0</id> <is_current>1</is_current> <is_released>0</is_released> <keyed_name>TT</keyed_name> <locked_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</locked_by_id> <major_rev>C</major_rev> <make_buy>Make</make_buy> <modified_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</modified_by_id> <modified_on>2017-12-04T03:03:28</modified_on> <name>TT123</name> <new_version>0</new_version> <not_lockable>0</not_lockable> <state>Preliminary</state> <unit>EA</unit> <item_number>TT</item_number> <itemtype>4F1AC04A2B484F3ABA4E20DB63808A88</itemtype> <permission_id> <Item isNew="1" isTemp="1" type="Permission" action="get"> <name>Customer</name> </Item> </permission_id> </Item> <Item type="Part" typeId="4F1AC04A2B484F3ABA4E20DB63808A88" id="C919C3C8CAA3405680A35EFBC0B27595" loadedPartialy="0" isDirty="1" LastModifiedOn="1512374887622" action="version" doGetItem="1" oldId="8821D59BCEC540978D2F246A5AD409C0"> <config_id keyed_name="TT" type="Part">5F7C0850DF1F4A84B6E03C7B85EFC074</config_id> <created_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id> <created_on>2017-12-04T02:49:42</created_on> <current_state keyed_name="Preliminary" type="Life Cycle State" name="Preliminary">72A2322564FE4193933CFB5339487A06</current_state> <generation>5</generation> <id keyed_name="TT" type="Part">8821D59BCEC540978D2F246A5AD409C0</id> <is_current>1</is_current> <is_released>0</is_released> <keyed_name>TT</keyed_name> <locked_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</locked_by_id> <major_rev>C</major_rev> <make_buy>Make</make_buy> <modified_by_id keyed_name="Super User" type="User">AD30A6D8D3B642F5A2AFED1A4B02BEFA</modified_by_id> <modified_on>2017-12-04T03:03:28</modified_on> <name>TT123</name> <new_version>1</new_version> <not_lockable>0</not_lockable> <state>Preliminary</state> <unit>EA</unit> <item_number>TT</item_number> <itemtype>4F1AC04A2B484F3ABA4E20DB63808A88</itemtype> <permission_id> <Item isNew="1" isTemp="1" type="Permission" action="get"> <name>Customer</name> </Item> </permission_id> </Item> Why isn't this working?
Children
No Data