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!

  • 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