How to Pass Values from onBeforeX to onAfterX Events
Copy
You want to pass some value from an onBefore (i.e., onBeforeUpdate) event to an onAfter (i.e., onAfterUpdate) event for data process handling.
Technique
Use the built-in function to add a variable, read a variable and remove a variable from the RequestState. This sample determines if there was a change made to the “Name” property of Part.
C#
OnBeforeUpdate event
//Get Part Name before change
Innovator inn = this.getInnovator();
Item myPart = inn.newItem(“Part”,"get”);
myPart.setID(this.getID());
myPart.setAttribute(“select”,"name”);
myPart=myPart.apply();
string prevName = myPart.getProperty(“name”);
RequestState.Add(“prevName”, prevName); //Add value to SessionState
return this;
OnAfterUpdate event
string prevName = (string)RequestState[“prevName”];
string curName = this.getProperty(“name”);
if (prevName != curName)
{
//Do some logic here
}
//Perform cleanup of RequestState
RequestState.Remove(“prevName”); //removes single key
// to remove all keys use RequestState.Clear();
return this;