Deleting a Record in OFBiz using Java

This is an example on how to delete a record in OFBiz using Java. I am assuming that the you have created the service of this method in you service.xml.

public static Map deletePerson(DispatchContext dctx, Map context) {
Map resultMap = ServiceUtil.returnSuccess();
String id = (String) context.get("id");

try {
GenericValue personGV = delegator.findOne("Person", UtilMisc.toMap("id", id), false);
if (personGV != null && !personGV.isEmpty()) {
personGV.remove();
}
} catch (GenericEntityException e) {
return ServiceUtil.returnError("Failed. " +e.getMessage());
}
return resultMap;
}

4 comments:

  1. You could do a .removeByPrimaryKey and save yourself a step... if you wanted.

    ReplyDelete
  2. you have a nice site. thanks for sharing this site. there are various kinds of ebooks are available here

    http://feboook.blogspot.com

    ReplyDelete
  3. .removeByPrimaryKey is a deprecated method.

    ReplyDelete
  4. <remove-value. I suggest you to use XML auto completion. Below, there is some useful information
    https://cwiki.apache.org/confluence/display/OFBIZ/Mini-Language+Guide

    ReplyDelete