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

PDF Books
Show collection (0 pages)
Collections help

Search

ERP 2.50:Developers Guide/Code Snippets/Process

ERP 2.50:Developers Guide

Index


Warning.png   This document is still a work in progress. It may contain inaccuracies or errors.

Creating a process

Why?

The information about creating procedures on the Developers Manual requires a previous knowledge to understand it correctly. As an entry point on procedures with Openbravo it's too hard. This doc tries to fill this gap.

What?

Let's say that we want to call a procedure passing the pricelist_id and the pricelist_version_id, to do some beautiful and wonderful code with this two variables. Both variables should be given using a little pop up windows to select them.

How?

Let's use a little example step by step to explain how it works.

1.- The first thing to do is define the procedure in the Application Dictionary (Report & Process)

   Fill in the fields Search Key, Name, Description. With the field 'Procedure' take special care because it is the name of the PL/SQL in the database.
   Procedure: CUS_FLIMSY_PLSQL
   Checkbox 'Report' and checkbox 'Jasper Report' must be disable.

2.- Now, define the parameters for the procedure. Go to the Tab 'Parameter' and create two parameters with different names. In this window four parameters are important.

   Name
   DB Column Name
   Reference
   Application Element

Fill in them so:

(1st Parameter)

   Name: Price List
   DB Column Name: M_PRICELIST_ID
   Reference: TableDir
   Application Element: M_Pricelist_ID - Price List

(2nd Parameter)

   Name: Price List Version
   DB Column Name: M_PRICELIST_VERSION_ID
   Reference: TableDir
   Application Element: M_Pricelist_Version_ID - Price List Version

3.- Now it's all done, to create the PL/SQL in the database, look at the following code, especially the comments on it, and use it as template.


 CREATE OR REPLACE PROCEDURE "TAD"."CUS_FLIMSY_PLSQL"
 (
    PInstance_ID IN NUMBER
 )
 IS
    --IDs 
    v_costpricelist_id NUMBER;
    v_costpricelistversion_id NUMBER;
 
    -- Logistice
    v_ResultStr VARCHAR2(2000):='';
    v_Message VARCHAR2(2000):='';
    v_Result NUMBER:=0; --    failure
    v_Record_ID NUMBER;
 
    --    Parameter
    TYPE RECORD IS REF CURSOR;
    Cur_Parameter RECORD;
 
 BEGIN
    --  Update AD_PInstance
    DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing') ;
 
    v_ResultStr:='PInstanceNotFound';
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'Y', NULL, NULL) ;
 
    -- This following piece of code is common to all the procedures in Openbravo
    -- it reads the parameters passed through the pop up windows
    -- using the tables AD_PInstance and AD_PInstance_Para
 
    -- Get Parameters
    v_ResultStr:='ReadingParameters';
    FOR Cur_Parameter IN
            (SELECT i.Record_ID,
            p.ParameterName,
            p.P_String,
            p.P_Number,
            p.P_Date
            FROM AD_PInstance i
                LEFT JOIN AD_PInstance_Para p
                ON i.AD_PInstance_ID=p.AD_PInstance_ID
            WHERE i.AD_PInstance_ID=PInstance_ID
            ORDER BY p.SeqNo
            )
            LOOP
                v_Record_ID:=Cur_Parameter.Record_ID;
               
                --Cur_Parameter.ParameterName get the 'DB Column Name' that we defined in the step 2
                IF(Cur_Parameter.ParameterName='M_PRICELIST_ID') THEN
                    v_costpricelist_id:=Cur_Parameter.P_Number;
                    DBMS_OUTPUT.PUT_LINE('  M_PRICELIST_ID=' || v_costpricelist_id) ;
                ELSIF(Cur_Parameter.ParameterName='M_PRICELIST_VERSION_ID') THEN
                   v_costpricelistversion_id:=Cur_Parameter.P_Number;
                   DBMS_OUTPUT.PUT_LINE('  M_PRICELIST_VERSION_ID=' || v_costpricelistversion_id);
                ELSE
                   DBMS_OUTPUT.PUT_LINE('Unknown Parameter= '||Cur_Parameter.ParameterName);
                   v_costpricelist_id:=99999;
                   v_costpricelistversion_id:=99999;
                END IF;
            END LOOP;
            -- Get Parameter
 
 
 --**************************************
 --Some beautiful and wonderful code here
 --**************************************
 
 
     v_Result:=1; --success (Green Box)
 
     v_Message:='Everything was OK';
     DBMS_OUTPUT.PUT_LINE(v_Message) ;
     DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished') ;
 
     AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', v_Result, v_Message);
 
 EXCEPTION       
 WHEN OTHERS THEN
    v_ResultStr:= '@ERROR=' || SQLERRM;
    DBMS_OUTPUT.PUT_LINE(v_ResultStr) ;
    ROLLBACK;
    AD_UPDATE_PINSTANCE(PInstance_ID, NULL, 'N', 0, v_ResultStr) ;
    RETURN;
 END;

4.- Create the new procedure in the left menu (General Setup ->Application -> Menu). Write a name for the procedure, this is the name that appears in the left menu. Select as an 'Action' the type 'Procedure', and select your newly created procedure (CUS_FLIMSY_PLSQL)

5.- Compile.

Note: For testing just a 'compile.development -Dtab=xxx' should be enough.


If the compilation was successful, launch the new created procedure from the left menu. A little pop up windows with two selectors should appear. Just select the desired pricelist_id and pricelistversion_id and execute your procedure.


And now what?

Come back to the Developers Manual and try to understand the rest key concepts. Now it should be easier to understand them.



ERP 2.50:Developers Guide/Code Snippets/Window and Tab | ERP 2.50:Developers Guide/Examples

Retrieved from "http://wiki.openbravo.com/wiki/ERP_2.50:Developers_Guide/Code_Snippets/Process"

This page has been accessed 2,995 times. This page was last modified on 14 June 2011, at 11:03. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.