Difference between revisions of "Script Callout"

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.
m
(See Also)
 
(2 intermediate revisions by 2 users not shown)
Line 40: Line 40:
 
  }
 
  }
 
  result = "";
 
  result = "";
 +
 +
= Sample Code for Setting Payment Bank Account =
 +
 +
This script will set the bank account on the Payment window based on the Tender Type and Credit Card Type.
 +
 +
On the Payment Table and Column, callout reference for Tender Type and Credit Card Type:
 +
@script:beanshell:payment_setpaymentprocessor
 +
 +
On the Rule Search Key:
 +
beanshell:payment_setpaymentprocessor
 +
 +
On the Rule Script:
 +
import org.compiere.model.MPayment;
 +
 +
if(A_Tab.getValue("TenderType") != null && A_Tab.getValue("CreditCardType") != null && A_Tab.getValue("CreditCardType") != "")
 +
{
 +
    MPayment pmt = new MPayment(A_Ctx, 0,null);
 +
    pmt.setTenderType(A_Tab.getValue("TenderType"));
 +
    pmt.setC_Currency_ID(A_Tab.getValue("C_Currency_ID"));
 +
    pmt.setCreditCardType(A_Tab.getValue("CreditCardType"));
 +
    pmt.setPaymentProcessor();
 +
    A_Tab.setValue("C_BankAccount_ID", pmt.getC_BankAccount_ID());
 +
    pmt = null;
 +
}
 +
else
 +
{
 +
    A_Tab.setValue("C_BankAccount_ID", 0);
 +
}   
 +
result="";
  
 
=Scripting Languages=
 
=Scripting Languages=
Line 62: Line 91:
 
*[http://scripting.dev.java.net/ Java Scripting]
 
*[http://scripting.dev.java.net/ Java Scripting]
 
*[[Callout]]
 
*[[Callout]]
 +
*[[ZH/Case-Study-01-Journal-31|Rule Engin / Script Callout / Script Process ]]- Chinese

Latest revision as of 01:03, 28 December 2010

Qss.jpg   {{#if: Carlos Ruiz, Quality Systems & Solutions (QSS)|This contribution was provided by Carlos Ruiz, Quality Systems & Solutions (QSS)|This contribution was provided by The Adempiere Community}}
{{#if: http://globalqss.com%7Chttp://globalqss.com%7Chttp://www.adempiere.com}}
{{{sf_ref}}}}}
Logo e-Evolution.png   {{#if: Víctor Pérez, E-Evolution (Libero)|This contribution was provided by Víctor Pérez, E-Evolution (Libero)|This contribution was provided by The Adempiere Community}}
{{#if: http://www.e-evolution.com%7Chttp://www.e-evolution.com%7Chttp://www.adempiere.com}}
{{{sf_ref}}}}}

 

Creating the Rule

Within the script you can use:

  • Window context variables start with a W_ prefix
  • Login context variables start with G_ prefix
  • Parameters for callout start with A_ prefix
    • A_WindowNo
    • A_Tab
    • A_Field
    • A_Value
    • A_OldValue
    • A_Ctx

01 BeanShell.png

Configure Callout from Table/Column

02 BeanShellCallout.png

  • This Callout can also be called from the Report & Process Window. Just remember to set in the Rule window from which Event Type are you calling this Rule Script.

Sample Code provided for copy/paste testing

On the Table and Column, callout reference:

@script:beanshell:BP_fillDescriptionFromName

On the Rule Search Key:

beanshell:BP_fillDescriptionFromName

On the Rule Script:

if (A_Tab.getValue("Name") != null) {
    A_Tab.setValue("Description", A_Tab.getValue("Name"));
}
result = "";

Sample Code for Setting Payment Bank Account

This script will set the bank account on the Payment window based on the Tender Type and Credit Card Type.

On the Payment Table and Column, callout reference for Tender Type and Credit Card Type:

@script:beanshell:payment_setpaymentprocessor

On the Rule Search Key:

beanshell:payment_setpaymentprocessor

On the Rule Script:

import org.compiere.model.MPayment;

if(A_Tab.getValue("TenderType") != null && A_Tab.getValue("CreditCardType") != null && A_Tab.getValue("CreditCardType") != "")
{
   MPayment pmt = new MPayment(A_Ctx, 0,null);
   pmt.setTenderType(A_Tab.getValue("TenderType"));
   pmt.setC_Currency_ID(A_Tab.getValue("C_Currency_ID"));
   pmt.setCreditCardType(A_Tab.getValue("CreditCardType"));
   pmt.setPaymentProcessor();
   A_Tab.setValue("C_BankAccount_ID", pmt.getC_BankAccount_ID());
   pmt = null;
}
else
{
   A_Tab.setValue("C_BankAccount_ID", 0);
}    
result="";

Scripting Languages

  • Now standard Adempiere has uploaded jars to work with groovy, jython and beanshell
  • to call a script from a Callout follow these sample syntax:
    • @script:beanshell:ValidateQtyOnHand
    • @script:groovy:ValidateQtyOnHand
    • @script:jython:ValidateQtyOnHand
  • When you create the rule, you have to set in the Search Key such as:
    • Search Key : beanshell:ValidateQtyOnHand
    • Search Key : groovy:ValidateQtyOnHand
    • Search Key : jython:ValidateQtyOnHand
  • Set the Event Type as Callout and Rule Type as JSR 223 Scripting APIs

See Also