View source | Discuss this page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Add page
Show collection (0 pages)
Collections help


How to implement Create New In Selectors

Bulbgraph.png   This works from Openbravo PR14Q4

In this this module there is an example of a selector with a selector with the 'create new' capability (among other things). All the implementation of this selector is in this changeset.

This module implements a selector called "Business Partner (Add New)" in the "Sales Order" window.

Let's review step by step how this selector has been built, focusing in the steps that this project implements.

CNIS TD 01.png
CNIS TD 02.png
CNIS TD 03.png
OB.OBPF.BPCreation = function (processWindow) {
  var i, j, theFormItems;
  if (!processWindow || !processWindow.enteredValues || !processWindow.theForm || !processWindow.theForm.items) {
  theFormItems = processWindow.theForm.items;
  for (i = 0; i < theFormItems.length; i++) {
    for (j = 0; j < processWindow.enteredValues.length; j++) {
      if (processWindow.enteredValues[j][theFormItems[i].name]) {

Since in this case the name of the form items equals the name of the selector columns, there is an iterative logic to match each "enteredValue" with each form item of the process.

public class BPCreationActionHandler extends BaseProcessActionHandler {
  private static final Logger log = Logger.getLogger(BPCreationActionHandler.class);
  protected JSONObject doExecute(Map<String, Object> parameters, String content) {
    JSONObject result = new JSONObject();
    try {
      result.put("refreshParent", false);
      String clientId = OBContext.getOBContext().getCurrentOrganization().getId();
      String orgId = OBContext.getOBContext().getCurrentClient().getId();
      JSONObject request = new JSONObject(content);
      if (request.has("inpadClientId")) {
        clientId = request.getString("inpadClientId");
      if (request.has("inpadOrgId")) {
        orgId = request.getString("inpadOrgId");
      JSONObject params = request.getJSONObject("_params");
      String searchKey = params.getString("searchKey");
      String name = params.getString("name");
      String bpCategoryId = params.getString("BPCat");
      BusinessPartner bp = OBProvider.getInstance().get(BusinessPartner.class);
      bp.setClient(OBDal.getInstance().get(Client.class, clientId));
      bp.setOrganization(OBDal.getInstance().get(Organization.class, orgId));
      bp.setBusinessPartnerCategory(OBDal.getInstance().get(Category.class, bpCategoryId));
      JSONObject setSelectorValueFromRecord = new JSONObject();
      JSONObject record = new JSONObject();
      JSONObject responseActions = new JSONObject();
      record.put("value", bp.getId());
      record.put("map", bp.getIdentifier());
      setSelectorValueFromRecord.put("record", record);
      responseActions.put("setSelectorValueFromRecord", setSelectorValueFromRecord);
      result.put("responseActions", responseActions);
    } catch (JSONException e) {
      log.error("Error in process", e);
    } catch (Exception e) {
      try {
        Throwable ex = DbUtility.getUnderlyingSQLException(e);
        String message = OBMessageUtils.translateError(ex.getMessage()).getMessage();
        JSONObject msg = new JSONObject();
        JSONObject responseActions = new JSONObject();
        msg.put("msgType", "error");
        msg.put("msgTitle", "Error");
        msg.put("msgText", message);
        msg.put("force", true);
        responseActions.put("showMsgInProcessView", msg);
        result.put("responseActions", responseActions);
        result.put("retryExecution", true);
      } catch (JSONException ex) {
        log.error("Error in process", e);
    } finally {
    return result;

Here with the "params.getString" the entered values in the form are obtained and then set in the "bp" (Business Partner). After the instance be saved, the "record" is built and returned, with the "id" as "value" and the "identifier" as "map" There is also some logic to catch errors and show them as a message.

Retrieved from ""

This page has been accessed 5,548 times. This page was last modified on 4 July 2014, at 17:41. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.