This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - My method for auto part naming makes ECO Express not to work?

BMoberg - Tuesday, May 13, 2014 10:31 AM:

I have created a simple method (see below) that generates a part name based on selected values.
This works great when creating and updating a preliminary part as it runs on both "onBeforeAdd" and "OnBeforeUpdate".

However, the problem is that since it runs on OnBeforeUpdate, the ECO Express doesn't work when the ECO-lifecycle is pushed from "Plan Review" to " In Work". (Error: Object reference not set to an instance of an object )
Probably because of the mastodon method "PE_ChangeItemTransition".
Perhaps the part somehow is updated by that method, and my method kicks off because of this (?)
 
My method is intended/needed to run only when manually creating or modifying a preliminary part.

Any suggestions on how to solve this issue?
I find it strange if I need to fix this in the method "PE_ChangeItemTransition".

(C# Server side "onBeforeAdd" and "OnBeforeUpdate".)
_________________________________________________________________________________________


var Value1 = this.getProperty("classification");
  
// Check if Screw and add name from selected properties
if (Value1.Contains("Screws"))
{
  string mat = this.getProperty("kol_screw_mec_material");
  string surf = this.getProperty("kol_screw_surface_treatment");
  string thread = this.getProperty("kol_screw_thread_type");
  string length = this.getProperty("kol_screw_length");
  string type = this.getProperty("kol_screw_type");
  string concatVal = "Screw " + type + " " + thread + "x" + length + " " + mat + " " + surf;
  this.setProperty("name",concatVal);
}
  
return this;



Brian - Tuesday, May 13, 2014 11:42 PM:

Hi Benny,

When the ECO-lifecycle is pushed from "In review" to "in work" is when the versioning magic happens and a new record is written to the database. So in this case a new Part item at rev "B" or whatever is created which kicks off your method.

The interesting part of this is what is causing the error.

I'm guessing 

var value1 = this.getProperty("classification");

is returning null since "this" should be there regardless.

Either:

Change this line to read:

var value1 = this.getProperty("classification","");

in which case you will be returned an empty string that should fail your test and so just continue or test for null and abort as appropriate.

The method is pretty short so there isn't going to be much of a performance hit in leaving it running even when it isn't strictly needed but you could also pass a dummy piece of aml to the method by inserting a aml into the context item from the Part form. Then you could test for this property and abort if not found.

Hope this helps,

Brian.



BMoberg - Thursday, May 15, 2014 4:38 AM:

Yes, that helped!
Thanks Brian!

Regards /Benny