How to get existing property value with server event onbeforeupdate

I am writing a method to check onbeforeupdate if an item has a perperty P value of A, then do something, such as rejecting update. However, if the user updated the property P value from A to B,  at the very transaction, even the original property value is A. The item.getproperty(P) returns the current updated, ready to be saved value of B, so my method would not work. Here is the question to all the guru here. How do I check the property value stored in the database of current item, not just the updated value that is about to be saved in an update event. Thank you very much for the help!

Parents
  • Hello,

    To do this kind of check, you'd need to perform a get on the item that's being updated. You can do this with the standard IOM API like the example below.

    Innovator inn = this.getInnovator();
    Item partBeforeUpdate = inn.newItem("Part""get");
    partBeforeUpdate.setID(this.getID());
    partBeforeUpdate.setAttribute("select""item_number"); // Select whatever property you want to check
    partBeforeUpdate = partBeforeUpdate.apply();
    string myPropVal = partBeforeUpdate.getProperty("item_number""");
    if (myPropVal == "MY TEST VALUE") {
        // Do some logic if the property is equal to your value
    else {
        // Otherwise do other logic
    }

    Hope this helps!

    Chris

    Christopher Gillis

    Aras Labs Software Engineer

  • Hi, Chris,


    I am also need help.

    If the value of the property changed from A to B when saving an Item. I can only get the A value,  but not B value for onBeforeUpdate Method.

    How to get the B value, which is being saved ? or If use onAfterUpdate, the vice-versa issue occur.

  • Hello,

    You do have access to both values in an onBeforeUpdate event. The new value will exist on the context item, this, inside the method. The old value can be queried for by using the sample code in my previous response.

    For example, if we're updating the item_number of a Part, the AML of that request would look like so:

    <AML>
        <Item type="Part" action="edit" id="YOUR_ITEM_ID">
            <item_number>New Item Number</item_number>
        </Item>
    </AML>

    And we can get this new updated value from the context item using:

    string oldPropVal = this.getProperty("item_number", "");

    Chris

Reply Children
No Data