Difference between revisions of "Script Process"
From iDempiere en
m (Reverted edits by Red1 (Talk); changed back to last version by CarlosRuiz) |
CarlosRuiz (talk | contribs) |
||
| Line 9: | Line 9: | ||
Within the script you can use: | Within the script you can use: | ||
| − | * Login context variables start with two | + | * Login context variables start with two dollar signs $$ |
| − | * Parameters for the process start with three | + | * Parameters for the process start with three dollar signs $$$, for example $$$Name |
| − | * If the parameter is a range then the parameters will be | + | * If the parameter is a range then the parameters will be $$$Name1 and $$$Name2 |
And the following predefined: | 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]] | [[Image:01_ScriptForProcess.png]] | ||
| Line 42: | Line 42: | ||
/* get Table Info */ | /* get Table Info */ | ||
| − | MTable table = new MTable ( | + | MTable table = new MTable ($$$Ctx, $$$AD_Table_ID, $$$TrxName); |
if (table.get_ID() == 0) | if (table.get_ID() == 0) | ||
| − | throw new IllegalArgumentException ("No AD_Table_ID=" + | + | throw new IllegalArgumentException ("No AD_Table_ID=" + $$$AD_Table_ID); |
String tableName = table.getTableName(); | String tableName = table.getTableName(); | ||
if (!tableName.startsWith("I")) | if (!tableName.startsWith("I")) | ||
| Line 50: | Line 50: | ||
/* Delete */ | /* Delete */ | ||
| − | String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + | + | String sql = "DELETE FROM " + tableName + " WHERE AD_Client_ID=" + $$$AD_Client_ID; |
| − | int no = DB.executeUpdate(sql, | + | int no = DB.executeUpdate(sql, $$$TrxName); |
| − | + | $$$ProcessInfo.addLog (0, null, null, "Deleted "+no+" rows from table "+tableName); | |
result = "OK"; | result = "OK"; | ||
Revision as of 20: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 dollar signs $$
- Parameters for the process start with three dollar signs $$$, 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
Configure the Process
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";


