Set "Item has BOM"-indicator

Hi,

To indicate that a Part has BOM or not I want to set a field (HasBOM) to 1 or 0

I have below server side code  triggered on onBeforeAdd and  OnBeforeUpdate on the Part item type

It works,

But I have to press save twice!? to have the field updated after I removed or added a BOM,
is there a way to have it updated directly on save???

Thanks for any idea

//Mikael

// Method to check if item has BOM and set HasBOM "

Innovator inn = this.getInnovator();
string issueID = this.getProperty("source_id","");

Item updatedBOM = inn.applyAML( "<AML>" + " <Item type='Part BOM' action='get' select='related(item_number)'>" + " <source_id>" + this.getID() + "</source_id>" + " <related_id>" + " <Item>" + " </Item>" + " </related_id>" + " </Item>" + "</AML>");


if (updatedBOM.getItemCount() > 0)

{
this.setProperty("hasbom", "1");
}
else
{
this.setProperty("hasbom", "0");
}

return this;

Parents
  • Hi Mikael

    My guess is, your method code updatedBOM.getItemCount() returns '0' count on OnBeforeAdd event and return '1' OnBeforeUpdate event. (when you press second time, it is onBeforeUpdate event). Instead of updating the hasbom field on each time part is updated or added, you can implementing on Part BOM item type (instead of Part) onbeforeAdd (update hasbom to 1) and onbeforeDelete (if count of Part BOM is 0, then update hasbom to '0'). or you can use onInsertRow and onDeleteRow events on Part BOM relationship type

    Currently, I trying to implement this in my local environment, if I'm able to finish, I will update code here.

    Thank You

    Gopikrishnan R

Reply
  • Hi Mikael

    My guess is, your method code updatedBOM.getItemCount() returns '0' count on OnBeforeAdd event and return '1' OnBeforeUpdate event. (when you press second time, it is onBeforeUpdate event). Instead of updating the hasbom field on each time part is updated or added, you can implementing on Part BOM item type (instead of Part) onbeforeAdd (update hasbom to 1) and onbeforeDelete (if count of Part BOM is 0, then update hasbom to '0'). or you can use onInsertRow and onDeleteRow events on Part BOM relationship type

    Currently, I trying to implement this in my local environment, if I'm able to finish, I will update code here.

    Thank You

    Gopikrishnan R

Children
No Data