public static MapupdatePerson(DispatchContext dctx, Map context) {
MapresultMap = ServiceUtil.returnSuccess();
//this is how you fetch the values from the request
String id = (String) context.get("id");
String firstName = (String) context.get("firstName");
String lastName = (String) context.get("lastName");
String gender = (String) context.get("gender");
String email = (String) context.get("email");
try {
GenericValue personGV = delegator.findOne("Person", UtilMisc.toMap("id", id), false);
if (personGV != null && !personGV.isEmpty()) {
personGV.put("firstName", firstName);
personGV.put("lastName", lastName);
personGV.put("gender", gender);
personGV.put("email", email);
personGV.store();
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError("Failed. " +e.getMessage());
}
return resultMap;
}
Updating a Record in OFBiz using Java
This is an example on how to update a record in OFBiz using Java as engine. I am assuming that the you have created the service of this method in you service.xml.
Labels:
delegator,
DispatchContext,
findOne,
GenericEntityException,
GenericValue,
Java,
Map,
OFBiz,
ServiceUtil,
store()
Subscribe to:
Post Comments (Atom)
Could you tell me how to update a record from a Java program that is not a service?
ReplyDeletehttp://stackoverflow.com/questions/11803591/how-does-one-get-the-dispatchcontext-in-ofbiz-from-a-java-program