Difference between revisions of "Script Process"

From iDempiere en
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Status: working in version > 3.3.1b<br>
 
 
Contributed by:<br>
 
Quality Systems & Solutions - QSS Ltda.<br>
 
[[User:CarlosRuiz|Carlos Ruiz]]
 
 
 
 
== Create the Rule ==
 
== Create the Rule ==
  
 
Within the script you can use:
 
Within the script you can use:
* Login context variables start with two dollar signs $$
+
* Login context variables start with G_ prefix
* Parameters for the process start with three dollar signs $$$, for example $$$Name
+
* Process Parameters for the process start with P_ prefix, for example P_Name
* If the parameter is a range then the parameters will be $$$Name1 and $$$Name2
+
* If the parameter is a range then the parameters will be P_Name1 and P_Name2
And the following predefined:
+
And the following predefined arguments:
* $$$Ctx - the context
+
* A_Ctx - the context
* $$$Trx - the transaction
+
* A_Trx - the transaction
* $$$TrxName
+
* A_TrxName
* $$$Record_ID
+
* A_Record_ID
* $$$AD_Client_ID
+
* A_AD_Client_ID
* $$$AD_User_ID
+
* A_AD_User_ID
* $$$AD_PInstance_ID
+
* A_AD_PInstance_ID
* $$$Table_ID
+
* A_Table_ID
 +
* A_Parameter - the array of parameters
 +
* A_ProcessInfo - the ProcessInfo object
  
 
[[Image:01_ScriptForProcess.png]]
 
[[Image:01_ScriptForProcess.png]]
Line 31: Line 26:
  
 
On the Report & Process:
 
On the Report & Process:
  @script:beanshell:ImportDelete
+
  @script:groovy:ImportDelete
  
 
On the Rule Search Key:
 
On the Rule Search Key:
  beanshell:ImportDelete
+
  groovy:ImportDelete
  
 
On the Rule Script:
 
On the Rule Script:
Line 42: Line 37:
 
   
 
   
 
  /* get Table Info */
 
  /* get Table Info */
  MTable table = new MTable ($$$Ctx, $$$AD_Table_ID, $$$TrxName);
+
  MTable table = new MTable (A_Ctx, P_AD_Table_ID, A_TrxName);
 
  if (table.get_ID() == 0)
 
  if (table.get_ID() == 0)
     throw new IllegalArgumentException ("No AD_Table_ID=" + $$$AD_Table_ID);
+
     throw new IllegalArgumentException ("No AD_Table_ID=" + P_AD_Table_ID);
 
  String tableName = table.getTableName();
 
  String tableName = table.getTableName();
 
  if (!tableName.startsWith("I"))
 
  if (!tableName.startsWith("I"))
Line 50: Line 45:
 
   
 
   
 
  /* Delete */
 
  /* Delete */
  String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + $$$AD_Client_ID;
+
  String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + A_AD_Client_ID;
  int no = DB.executeUpdate(sql, $$$TrxName);
+
  int no = DB.executeUpdate(sql, A_TrxName);
  $$$ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName);
+
  A_ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName);
 
  result = "OK";
 
  result = "OK";
  
Line 58: Line 53:
 
*[[Script Callout]]
 
*[[Script Callout]]
 
*[[Script ModelValidatorLogin]]
 
*[[Script ModelValidatorLogin]]
 +
*[[Script_ModelValidator]]
 +
*[[Rule snippets]]
 +
 +
[[Category:Development]]
 +
[[Category:Code snippets]]

Latest revision as of 09:31, 25 February 2021

Create the Rule

Within the script you can use:

  • Login context variables start with G_ prefix
  • Process Parameters for the process start with P_ prefix, for example P_Name
  • If the parameter is a range then the parameters will be P_Name1 and P_Name2

And the following predefined arguments:

  • A_Ctx - the context
  • A_Trx - the transaction
  • A_TrxName
  • A_Record_ID
  • A_AD_Client_ID
  • A_AD_User_ID
  • A_AD_PInstance_ID
  • A_Table_ID
  • A_Parameter - the array of parameters
  • A_ProcessInfo - the ProcessInfo object

01 ScriptForProcess.png

Configure the Process

02 ProcessWithScript.png

Code provided for copy/paste testing

On the Report & Process:

@script:groovy:ImportDelete

On the Rule Search Key:

groovy: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 (A_Ctx, P_AD_Table_ID, A_TrxName);
if (table.get_ID() == 0)
    throw new IllegalArgumentException ("No AD_Table_ID=" + P_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=" + A_AD_Client_ID;
int no = DB.executeUpdate(sql, A_TrxName);
A_ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName);
result = "OK";

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.