<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_a_Pick_and_Execute_Process</id>
	<title>How to create a Pick and Execute Process - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_a_Pick_and_Execute_Process"/>
	<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Pick_and_Execute_Process&amp;action=history"/>
	<updated>2026-04-06T15:23:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Pick_and_Execute_Process&amp;diff=263&amp;oldid=prev</id>
		<title>Wikiadmin: Created page with &quot;== Introduction ==  ''Pick and Execute (P&amp;E)'' is a case of ''Process Definition'' with ''Standard'' UI pattern.  This how to w...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Pick_and_Execute_Process&amp;diff=263&amp;oldid=prev"/>
		<updated>2018-10-15T13:41:38Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Introduction ==  &amp;#039;&amp;#039;Pick and Execute (P&amp;amp;E)&amp;#039;&amp;#039; is a case of &lt;a href=&quot;/index.php/How_to_create_a_Standard_Process_Definition&quot; title=&quot;How to create a Standard Process Definition&quot;&gt;&amp;#039;&amp;#039;Process Definition&amp;#039;&amp;#039; with &amp;#039;&amp;#039;Standard&amp;#039;&amp;#039; UI pattern&lt;/a&gt;.  This how to w...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
''Pick and Execute (P&amp;amp;E)'' is a case of [[How_to_create_a_Standard_Process_Definition|''Process Definition'' with ''Standard'' UI pattern]].&lt;br /&gt;
&lt;br /&gt;
This how to will add a new Pick and Execute process and associate it with the Sales Order window.&lt;br /&gt;
&lt;br /&gt;
The implementation requires development experience. See the following concept pages for background information on action handlers and javascript development:&lt;br /&gt;
* [[Openbravo_3_Architecture#Implementing_Server_Side_Actions_callable_from_the_client|Action Handler]]&lt;br /&gt;
* [[Client_Side_Development_and_API]]&lt;br /&gt;
* [[JavaScript_Coding_Conventions]]&lt;br /&gt;
&lt;br /&gt;
It also makes sense to study the following page: [[Openbravo_3_Architecture]].&lt;br /&gt;
&lt;br /&gt;
{{(!)| The Pick and Execute processes explained in this how to, is available from '''3.0MP6'''}}&lt;br /&gt;
&lt;br /&gt;
== Example Module ==&lt;br /&gt;
This howto is supported by an example module which shows examples of the code shown and discussed. &lt;br /&gt;
&lt;br /&gt;
The code of the example module can be downloaded from this mercurial repository: https://code.openbravo.com/erp/mods/org.openbravo.client.application.examples/&lt;br /&gt;
&lt;br /&gt;
The example module is available through the Central Repository (See 'Client Application Examples'), for more information see the [[Projects/ExamplesClientApplication|Examples Client Application]] project page.&lt;br /&gt;
&lt;br /&gt;
== Steps to implement the Process ==&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
The P&amp;amp;E processes take advantage of the same foundation concepts in the Application Dictionary. We'll be using the ''Window, Tabs and Fields'' for defining the editable grid that will be shown, a new ''Reference'' for the parameter of the process; and then implementing an ''action handler'' that will get executed when the user hits the &amp;quot;Done&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
=== Implementation ===&lt;br /&gt;
==== Defining the Window ====&lt;br /&gt;
* Create a new window&lt;br /&gt;
* Fill the required fields&lt;br /&gt;
* Select '''Pick and Execute''' as window type&lt;br /&gt;
&lt;br /&gt;
[[Image:pne1.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
* Following the same concepts, you require have a '''Table''' as your data-source. Note: If you need to mix information from several tables, you have different options:&lt;br /&gt;
** A database view used to create a table in [[How_to_create_a_Table|Application Dictionary]].&lt;br /&gt;
** A table based on an [[How_to_create_a_HQL_Based_Table|HQL query]]&lt;br /&gt;
** A table based on a [[How_to_Create_a_Table_Based_on_a_User_Defined_Datasource|manual datasource]]&lt;br /&gt;
&lt;br /&gt;
[[Image:pne2.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
* Create the necessary fields that will turn into the columns of the grid. Pick a '''Column'''  and pay attention to some important properties:&lt;br /&gt;
** '''Displayed:''' This must be checked in order to generate a field. If Displayed is unchecked no field will be generated.&lt;br /&gt;
** '''Read Only:''' Most of the times all the fields will be read-only. If you want a user to be able to modify some data, e.g. quantity leave it unchecked&lt;br /&gt;
** '''Show in Grid View:''' Defines if the field will be shown in the grid. You can define a Field as displayed but not shown in grid, so a field will get generated but not shown. This is useful for retrieving data to the grid and send it to the process.&lt;br /&gt;
** '''Grid Position:''' Defines the sequence of the fields in the grid&lt;br /&gt;
&lt;br /&gt;
[[Image:pne3.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
==== Defining the Reference ====&lt;br /&gt;
After defining the window, you need to define a new Reference.&lt;br /&gt;
* Create a new Reference&lt;br /&gt;
* Select in the Base Reference drop down: Window Reference&lt;br /&gt;
* Save&lt;br /&gt;
&lt;br /&gt;
[[Image:pne4.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
* Move to Window tab&lt;br /&gt;
* Create a new record&lt;br /&gt;
* Select your newly created window&lt;br /&gt;
* Save&lt;br /&gt;
&lt;br /&gt;
[[Image:pne5.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
==== Defining the Process ====&lt;br /&gt;
There is a new window for processes: '''Process Definition'''&lt;br /&gt;
&lt;br /&gt;
* Open the Process Definition window&lt;br /&gt;
* Create a new record&lt;br /&gt;
* Define the UI pattern: Standard (Parameters defined in Dictionary)&lt;br /&gt;
* Set the Handler (Java class implementing the process)&lt;br /&gt;
* Save&lt;br /&gt;
&lt;br /&gt;
[[Image:pne6.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
===== Parameters =====&lt;br /&gt;
{{(!)|Window Reference is the an implementation of a ''rich parameter''}}&lt;br /&gt;
&lt;br /&gt;
* Move to Parameters tab&lt;br /&gt;
* Create a new record&lt;br /&gt;
* Fill the required fields. The name of the parameter will be the name shown in the title of the running process.&lt;br /&gt;
* Select Window Reference&lt;br /&gt;
* Pick the Window you defined previously&lt;br /&gt;
* Save&lt;br /&gt;
&lt;br /&gt;
[[Image:pne7.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
==== Adding a button to Sales Order ====&lt;br /&gt;
===== Create a Column =====&lt;br /&gt;
As you know, you required to have a new column to associated it to a button.&lt;br /&gt;
{{(!)| You can check other how-to if you are not confident with this process, e.g. [[How_to_add_a_field_to_a_Window_Tab]]}}&lt;br /&gt;
&lt;br /&gt;
* Create a new column in the C_Order table. PostgreSQL syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;sql&amp;quot;&amp;gt;ALTER TABLE c_order ADD COLUMN em_obexapp_pick1 character(1);&lt;br /&gt;
ALTER TABLE c_order ALTER COLUMN em_obexapp_pick1 SET DEFAULT 'N'::bpchar;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Go to: Tables and Columns&lt;br /&gt;
* Open the C_Order record&lt;br /&gt;
* Execute: '''Create Columns from DB''' process&lt;br /&gt;
* Move to the Columns Tab&lt;br /&gt;
* Pick the newly created column&lt;br /&gt;
* Change the reference from: Yes/No to Button&lt;br /&gt;
* Pick your defined process&lt;br /&gt;
&lt;br /&gt;
[[Image:pne8.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
===== Create a Field =====&lt;br /&gt;
* Go to Windows, Tabs and Fields&lt;br /&gt;
* Search for Sales Order&lt;br /&gt;
* Create a new Field associated with your column&lt;br /&gt;
&lt;br /&gt;
[[Image:pne9.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
==== Java Implementation ====&lt;br /&gt;
As mentioned earlier you should be confident with the concept of an [[Openbravo_3_Architecture#ActionHandler:_server_side.2C_calling_from_the_client|action handler]].&lt;br /&gt;
&lt;br /&gt;
In the case of a Pick and Execute action handler, you must extend from '''BaseProcessActionHandler''' and implement the '''doExecute''' method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;/*&lt;br /&gt;
 *************************************************************************&lt;br /&gt;
 * The contents of this file are subject to the Openbravo  Public  License&lt;br /&gt;
 * Version  1.1  (the  &amp;quot;License&amp;quot;),  being   the  Mozilla   Public  License&lt;br /&gt;
 * Version 1.1  with a permitted attribution clause; you may not  use this&lt;br /&gt;
 * file except in compliance with the License. You  may  obtain  a copy of&lt;br /&gt;
 * the License at http://www.openbravo.com/legal/license.html&lt;br /&gt;
 * Software distributed under the License  is  distributed  on  an &amp;quot;AS IS&amp;quot;&lt;br /&gt;
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the&lt;br /&gt;
 * License for the specific  language  governing  rights  and  limitations&lt;br /&gt;
 * under the License.&lt;br /&gt;
 * The Original Code is Openbravo ERP.&lt;br /&gt;
 * The Initial Developer of the Original Code is Openbravo SLU&lt;br /&gt;
 * All portions are Copyright (C) 2011 Openbravo SLU&lt;br /&gt;
 * All Rights Reserved.&lt;br /&gt;
 * Contributor(s):  ______________________________________.&lt;br /&gt;
 ************************************************************************&lt;br /&gt;
 */&lt;br /&gt;
package org.openbravo.client.application.examples;&lt;br /&gt;
&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
&lt;br /&gt;
import org.apache.log4j.Logger;&lt;br /&gt;
import org.codehaus.jettison.json.JSONArray;&lt;br /&gt;
import org.codehaus.jettison.json.JSONObject;&lt;br /&gt;
import org.openbravo.client.application.ApplicationConstants;&lt;br /&gt;
import org.openbravo.client.application.process.BaseProcessActionHandler;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * @author iperdomo&lt;br /&gt;
 * &lt;br /&gt;
 */&lt;br /&gt;
public class PickExampleActionHandler extends BaseProcessActionHandler {&lt;br /&gt;
&lt;br /&gt;
  private static final Logger log = Logger.getLogger(PickExampleActionHandler.class);&lt;br /&gt;
&lt;br /&gt;
  @Override&lt;br /&gt;
  protected JSONObject doExecute(Map&amp;lt;String, Object&amp;gt; parameters, String content) {&lt;br /&gt;
    try {&lt;br /&gt;
      JSONObject request = new JSONObject(content);&lt;br /&gt;
&lt;br /&gt;
      log.info(&amp;quot;&amp;gt;&amp;gt; parameters: &amp;quot; + parameters);&lt;br /&gt;
      // log.info(&amp;quot;&amp;gt;&amp;gt; content:&amp;quot; + content);&lt;br /&gt;
&lt;br /&gt;
      // _selection contains the rows that the user selected.&lt;br /&gt;
      JSONArray selection = new JSONArray(&lt;br /&gt;
          request.getString(ApplicationConstants.SELECTION_PROPERTY));&lt;br /&gt;
&lt;br /&gt;
      log.info(&amp;quot;&amp;gt;&amp;gt; selected: &amp;quot; + selection);&lt;br /&gt;
&lt;br /&gt;
      // _allRows contains all the rows available in the grid&lt;br /&gt;
      JSONArray allRows = new JSONArray(request.getString(ApplicationConstants.ALL_ROWS_PARAM));&lt;br /&gt;
&lt;br /&gt;
      log.info(&amp;quot;&amp;gt;&amp;gt; allRows: &amp;quot; + allRows);&lt;br /&gt;
&lt;br /&gt;
      // A Pick and Execute process can have several buttons (buttonList)&lt;br /&gt;
      // You can know which button was clicked getting the value of _buttonValue&lt;br /&gt;
      log.info(&amp;quot;&amp;gt;&amp;gt; clicked button: &amp;quot; + request.getString(ApplicationConstants.BUTTON_VALUE));&lt;br /&gt;
&lt;br /&gt;
      return request;&lt;br /&gt;
    } catch (Exception e) {&lt;br /&gt;
      log.error(&amp;quot;Error processing request: &amp;quot; + e.getMessage(), e);&lt;br /&gt;
    }&lt;br /&gt;
    return new JSONObject();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Testing the Process ==&lt;br /&gt;
Since you have changed the structure of some Entity by adding a new column, you need to restart the tomcat server.&lt;br /&gt;
&lt;br /&gt;
* After restarting, you should be able to go to the Sales Order window and see a new button.&lt;br /&gt;
&lt;br /&gt;
[[Image:pne10.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
* When clicking the button, a new process window shows up. The user can pick, filter, modify according to the window definition, and click &amp;quot;Done&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[Image:pne11.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
== Advanced Topics ==&lt;br /&gt;
&lt;br /&gt;
=== Selecting by default ===&lt;br /&gt;
&lt;br /&gt;
Your data-source (table or view) defined in the Tab, can set which rows will be selected by default when the user launches the process. You just need to create a column c_ob_selected, this will turn into a ''obSelected'' property in the generated entity. When the value of this column is ''''Y'''', the row will be selected by default. Here you have an working example: [https://code.openbravo.com/erp/devel/pi/file/c5b8d03ac83c/src-db/database/model/views/M_RM_RECEIPT_PICK_EDIT.xml#l7 M_RM_RECEIPT_PICK_EDIT.xml].&lt;br /&gt;
&lt;br /&gt;
Note that when registering the column in the Application Dictionary the '''Yes/No''' reference must be used.&lt;br /&gt;
&lt;br /&gt;
=== Validation Function ===&lt;br /&gt;
&lt;br /&gt;
You can define at Field level a JavaScript validation function. In an editable field when the user enters a value, this function will get executed.&lt;br /&gt;
&lt;br /&gt;
* Go to Window, Tabs and Fields&lt;br /&gt;
* Pick your window and the tab&lt;br /&gt;
* Go to the Quantity field&lt;br /&gt;
&lt;br /&gt;
[[Image:pne12.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
==== JavaScript Definition ====&lt;br /&gt;
&lt;br /&gt;
* Your Component Provider needs to register a new global resource. If you are not familiar with this, check: [[Openbravo_3_Architecture#Component_Provider]]&lt;br /&gt;
* If your function returns false, the cell will be marked with an error&lt;br /&gt;
* In your JavaScript define a validation function, e.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;OB.OBEXAPP.PNE = {};&lt;br /&gt;
&lt;br /&gt;
OB.OBEXAPP.PNE.validate = function (item, validator, value, record) {&lt;br /&gt;
  // item has access to grid: item.grid&lt;br /&gt;
  // from the grid you can get all selected records and edited values, e.g.&lt;br /&gt;
  //   * item.grid.getSelection()&lt;br /&gt;
  //   * item.grid.getEditedRecord()&lt;br /&gt;
  // grid has access to view: grid.view&lt;br /&gt;
  // view has access to parentWindow: view.parentWindow (the window running the process)&lt;br /&gt;
  // parentWindow has access to currentView&lt;br /&gt;
  // currentView has getContextInfo&lt;br /&gt;
  // debugger;&lt;br /&gt;
  if(window.console) {&lt;br /&gt;
    console.log('validation function!', value);&lt;br /&gt;
  }&lt;br /&gt;
  return true;&lt;br /&gt;
};&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info on the capabilities of the grid in the SmartClient API documentation: [http://www.smartclient.com/docs/8.1/a/b/c/go.html#class..ListGrid ListGrid]&lt;br /&gt;
&lt;br /&gt;
=== Selection Function ===&lt;br /&gt;
&lt;br /&gt;
You could also define a selection function, at Tab level. This function will get called when the user select/unselect a row.&lt;br /&gt;
&lt;br /&gt;
[[Image:pne13.png|center|thumb|640px]]&lt;br /&gt;
&lt;br /&gt;
And define a JavaScript function in your loaded static .js file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;OB.OBEXAPP.PNE.selectionChanged = function (grid, record, recordList) {&lt;br /&gt;
  if (window.console) {&lt;br /&gt;
    console.log('selection function!');&lt;br /&gt;
    console.log(grid, record, recordList);&lt;br /&gt;
  }&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to change any value of the selected record, you have to use the following instruction:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;grid.setEditValue(grid.getRecordIndex(record), columnName, newColumnValue)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Performing Several Actions after Execution ===&lt;br /&gt;
&lt;br /&gt;
After the process is executed, a series of actions can be taken. How to do it is explained [[How_to_create_a_Standard_Process_Definition#Returning_Several_Actions|here]].&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;/div&gt;</summary>
		<author><name>Wikiadmin</name></author>
		
	</entry>
</feed>