Openbravo Forum End of Life Notice

Dear Openbravo Forum User,

Because of continued very low usage we decided to stop the forums on 31st of August 2017

In case of questions: webmaster "at" openbravo.com

Event Handler

<<

Giovanni Garofalo

Posts: 5

Joined: Wed Mar 30, 2011 8:36 am

Post Fri Jul 08, 2011 4:46 pm

Event Handler

Hi,

I'm working with OB 3.00 MP0
I need to create an Event Handler on Work Requirement windows,
In onSave Event I need to insert some records into a new sub-tab.

I followed this how-to http://wiki.openbravo.com/wiki/How_to_i ... nt_handler ,
but in my case it doesn't works correctly.
It doesn't saves any records in sub-tab, but it saves only the Work Requirement record.

My code is:

public void onSave(@Observes EntityNewEvent event) {
if (!isValidEvent(event)) {
return;
}
final Entity workRequirementEntity = ModelProvider.getInstance().getEntity(
WorkRequirement.ENTITY_NAME);
final WorkRequirement workRequirement = (WorkRequirement) event.getTargetInstance();
ProcessPlan processPlan = workRequirement.getProcessPlan();
Date wrCreationDate = workRequirement.getWRCreationDate();
ProcessPlanDAO ppDao = ProcessPlanDAO.singleton();
List<OperationProduct> operationProducts = ppDao.getFinalOperationProductByProcessPlan(
processPlan.getId(), wrCreationDate); // this method return 1 record...

final Property outputProperty = workRequirementEntity
.getProperty(WorkRequirement.PROPERTY_GSCWORKOUTPRODUCTLIST);
@SuppressWarnings("unchecked")
final List<Object> outputs = (List<Object>) event
.getCurrentState(outputProperty);
if (operationProducts != null) {
for (OperationProduct op : operationProducts) {
final GSCWorkOptputProduct outputProduct = OBProvider.getInstance().get(
GSCWorkOptputProduct.class);
// outputProduct.setNewOBObject(true);
// outputProduct.setActive(true);
// outputProduct.setCreatedBy(workRequirement.getCreatedBy());
// outputProduct.setCreationDate(workRequirement.getCreationDate());
// outputProduct.setUpdated(workRequirement.getUpdated());
// outputProduct.setUpdatedBy(workRequirement.getUpdatedBy());
outputProduct.setWorkRequirement(workRequirement);
// outputProduct.setClient(workRequirement.getClient());
// outputProduct.setOrganization(workRequirement.getOrganization());
outputProduct.setProduct(op.getProduct());

outputs.add(outputProduct);

}
}

System.err.println("WorkRequirement " + ((WorkRequirement) event.getTargetInstance()).getId()
+ " is being created");
}




Can someone help me?


Thanks&Regards,

Giovanni Garofalo
<<

Silambarasan Sekar

Posts: 4

Joined: Fri Sep 03, 2010 11:26 am

Location: Chennai , India

Post Sat May 19, 2012 4:54 am

Re: Event Handler

Hi,
From my understanding, i think you are not saving the object to the database .Please try the following code inside the for loop at the end of the statement.

  Code:
OBDal.getInstance().save("Your Object");
Thanks & Regards,

Silambarasan Sekar,
www.qualiantech.com

Return to Openbravo Exchange Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Website Terms


Designed by ST Software for PTF.