Configuring a Custom Trigger to Use a Custom Object
Prerequisite:
Perform the below steps before installing an application
- Download custom.zip file and extract.
- Copy customt.jar to following war file or tomcat installation path. Better to
copy to war files to avoid problem when you are working in cluster
environments.
- master/WEB-INF/lib (tomcat/webapps/master/WEB-INF/lib)
- prod1/WEB-INF/lib (tomcat/webapps/master/WEB-INF/lib). Copy to all prod machines.
- rest/WEB-INF/lib (tomcat/webapps/rest/WEB-INF/lib)
- webapi/WEB-INF/lib (tomcat/webapps/webapi/WEB-INF/lib)
- search/WEB-INF/lib (tomcat/webapps/search/WEB-INF/lib)
- storage/WEB-INF/lib (tomcat/webapps/strorage/WEB-INF/lib)
- Update event.xml to include Custom trigger configure details, from Platform 5.0 you can configure this from System console. Follow this link to add new entry to events.xml . With out this change you can’t install this application, since this application object configured with custom trigger.
- If you want to use Custom Object in formual (sample application include this feature) , update following shared property, CustomClassFilter = com.custom.CustomObject . More details about Custom Object are available in below section. From Platform 5.0 shared properties can be updated from system Console. If you don’t configure this property, Custom Object Field column displays error message.
- Restart your Tomcat
Getting Started
This application demonstrates how you can configure Custom Trigger and how you can use Custom Object in Platform. This Application has two object Object A, Object B and they are related to each other with relationship of M:M.
Object A – configured with Custom Trigger and used Custom Object in Custom Object Field formula field. In below sections, we will see in details about Custom Trigger and Custom Objects.
Object B – Have integer field configured which will be updated by Custom Trigger.
Custom Trigger
Custom Trigger can be developed and deployed only in the private cloud. Refer Developing a Custom Trigger in Platform. Sample custom trigger attached to development kit only run an Application that have at least two objects and both are related, also when you configure trigger for an object other side related object should have integer field.
Sample custom trigger code run on related object records, increment integer value of related object by 100 on each run, when value exceeds 1000, it throws error.
After configuring the custom trigger, the new custom trigger itemwill be available in the Trigger page. When you select the custom trigger, the Tirgger configuration page view will appear. Configure Relationship Name and Related Object integer field name from UI as shown in the sample screenshot below.
These two values are persisted and will be used by custom trigger code when it is run.
Following code is used to render these two fields in UI (CustomTriggerConfig.java)
Following code is used to persist the value to Trigger properties (CustomTriggerConfig.java)
Following code uses the above two values when trigger runs (CustomTrigger.java)
Custom Object
Custom Object can be used in Platform formulas. In order to use custom object user should make Custom Object available in tomcat class path. Sample attachment has CustomObject.java and this class is made part of customt.jar and copied as mentioned. You can build separate jar and copy jar to all war files as mentioned in the prerequisite section.
After you copy jar you should update following shared property
CustomClassFilter=Regular expression which matches classes you want to allow
Below section provided sample how to use Custom Object in Platform.
Sample
CustomClassFilter = com.custom.CustomObject
Formula field, returns number of related items
CustomObject.java
Sample class written to wrap simple ArrayList functionality, you are free to write this class as complex as you need.