Difference between revisions of "Developing codeunits"

From TempusServa wiki
Jump to navigation Jump to search
old>Admin
old>Admin
Line 41: Line 41:
   '''dk.tempusserva.MyExampleCodeunit.'''myParameter
   '''dk.tempusserva.MyExampleCodeunit.'''myParameter


== State variables ==
== Session variables ==
 
Variables can have a cope of either
* Request
* User session
* Application
 
For permanent variables user server configurations.
 
=== Request variables ===
 
 
=== User session variables ===
Acces the '''SessionValue''' attribute in  the '''Security''' object
* public boolean hasSessionValue(String name)
* public void setSessionValue(String name, boolean value)
* public int getSessionInteger(String name, int defaultValue)
* public int getSessionInteger(String name)
* public void setSessionInteger(String name, int value)
* public String getSessionString(String name, String defaultValue)
* public String getSessionString(String name)
* public void setSessionString(String name, String value)
 
Certain special user properties can also be accessed from the '''Security''' object
* public boolean hasProperty(String name)   
* public String getProperty(String name)
 
=== Application variables ===


== Different codeunit types ==
== Different codeunit types ==

Revision as of 16:08, 15 September 2018

Steps for creating a new codeunit

  1. Create a new Java project in your favorite IDE
  2. Import the p2eShared.jar in the project
  3. Create a new class:
    1. The abstract parts are found in: dk.p2e.blanket.codeunit
    2. Implement all abstract methods
    3. Code the method bodies (normally "execute")
  4. Compile and build
  5. Deploy to webservser: [Application]\WEB-INF\lib

After first test of the codeunit a server reboot is needed for each redeployment, as there is no way of removing the loaded classes from memory.

Error handling

Exceptions are handled by themselves using the errorRegistration(Exception e) method.

In case the errors are not caught by the codeunit itself, the generic error handler takes over

  1. Logs the error in the eventlog
  2. Returns a standard error page to the user

Other debugging options include log4j and specialized TempusServa Systemout.print functions (yes, the class name is "Systemout").

 Systemout.println( "hello world" );
 Systemout.printSql( myStatment );

Configuration / parameters

Parameters are delivered through the method call, packed in a nice <String> Hashtable for easy access. Please note that values are sent as-is, so make sure to escape values before DB operations using

 DbConnection.escapeSql(String s); 

Configurations can be stored using the getConfiguration methods of the command object. These values can be editedthrough the designer, depending on the Codeunit type

  • System configurations: Designer > Modules > Static content
  • Solution configurations: Designer > [Solution] > Advanced > Configurations

Value names will be prefixed with Class simple name - example + "."

 dk.tempusserva.MyExampleCodeunit.myParameter

Session variables

Variables can have a cope of either

  • Request
  • User session
  • Application

For permanent variables user server configurations.

Request variables

User session variables

Acces the SessionValue attribute in the Security object

  • public boolean hasSessionValue(String name)
  • public void setSessionValue(String name, boolean value)
  • public int getSessionInteger(String name, int defaultValue)
  • public int getSessionInteger(String name)
  • public void setSessionInteger(String name, int value)
  • public String getSessionString(String name, String defaultValue)
  • public String getSessionString(String name)
  • public void setSessionString(String name, String value)

Certain special user properties can also be accessed from the Security object

* public boolean hasProperty(String name)    
* public String getProperty(String name)

Application variables

Different codeunit types

Please read the: Codeunit reference

Most likely you will need to create a Codeunit/Formevents that will allow specific changes for a solution, during views, updates or exports.

Most interactions wil require interaction with the following objects

  • Security
  • Command
  • DbConnection
  • EventHandler