Difference between revisions of "Script Process"

From iDempiere en
(redirecting to Script Callout)
m (Reverted edits by Red1 (Talk); changed back to last version by CarlosRuiz)
Line 1: Line 1:
#REDIRECT [[Script Callout]]
+
Status: working in version > 3.3.1b<br>
 +
 
 +
Contributed by:<br>
 +
Quality Systems & Solutions - QSS Ltda.<br>
 +
[[User:CarlosRuiz|Carlos Ruiz]]
 +
 
 +
 
 +
== Create the Rule ==
 +
 
 +
Within the script you can use:
 +
* Login context variables start with two underscores __
 +
* Parameters for the process start with three underscores ___, for example ___Name
 +
* If the parameter is a range then the parameters will be ___Name1 and ___Name2
 +
And the following predefined:
 +
* ___Ctx - the context
 +
* ___Trx - the transaction
 +
* ___TrxName
 +
* ___Record_ID
 +
* ___AD_Client_ID
 +
* ___AD_User_ID
 +
* ___AD_PInstance_ID
 +
* ___Table_ID
 +
 
 +
[[Image:01_ScriptForProcess.png]]
 +
 
 +
== Configure the Process ==
 +
 
 +
[[Image:02_ProcessWithScript.png]]
 +
 
 +
== Code provided for copy/paste testing ==
 +
 
 +
On the Report & Process:
 +
@script:beanshell:ImportDelete
 +
 
 +
On the Rule Search Key:
 +
beanshell:ImportDelete
 +
 
 +
On the Rule Script:
 +
import org.compiere.model.MTable;
 +
import org.compiere.util.DB;
 +
import org.compiere.util.Msg;
 +
 +
/* get Table Info */
 +
MTable table = new MTable (___Ctx, ___AD_Table_ID, ___TrxName);
 +
if (table.get_ID() == 0)
 +
    throw new IllegalArgumentException ("No AD_Table_ID=" + ___AD_Table_ID);
 +
String tableName = table.getTableName();
 +
if (!tableName.startsWith("I"))
 +
    throw new IllegalArgumentException ("Not an import table = " + tableName);
 +
 +
/* Delete */
 +
String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + ___AD_Client_ID;
 +
int no = DB.executeUpdate(sql, ___TrxName);
 +
___ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName);
 +
result = "OK";

Revision as of 10:30, 26 January 2008

Status: working in version > 3.3.1b

Contributed by:
Quality Systems & Solutions - QSS Ltda.
Carlos Ruiz


Create the Rule

Within the script you can use:

  • Login context variables start with two underscores __
  • Parameters for the process start with three underscores ___, for example ___Name
  • If the parameter is a range then the parameters will be ___Name1 and ___Name2

And the following predefined:

  • ___Ctx - the context
  • ___Trx - the transaction
  • ___TrxName
  • ___Record_ID
  • ___AD_Client_ID
  • ___AD_User_ID
  • ___AD_PInstance_ID
  • ___Table_ID

01 ScriptForProcess.png

Configure the Process

02 ProcessWithScript.png

Code provided for copy/paste testing

On the Report & Process:

@script:beanshell:ImportDelete

On the Rule Search Key:

beanshell:ImportDelete

On the Rule Script:

import org.compiere.model.MTable;
import org.compiere.util.DB;
import org.compiere.util.Msg;

/* get Table Info */
MTable table = new MTable (___Ctx, ___AD_Table_ID, ___TrxName);
if (table.get_ID() == 0)
    throw new IllegalArgumentException ("No AD_Table_ID=" + ___AD_Table_ID);
String tableName = table.getTableName();
if (!tableName.startsWith("I"))
    throw new IllegalArgumentException ("Not an import table = " + tableName);

/* Delete */
String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + ___AD_Client_ID;
int no = DB.executeUpdate(sql, ___TrxName);
___ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName);
result = "OK";
Cookies help us deliver our services. By using our services, you agree to our use of cookies.