CloudIO Docs
  • CloudIO Platform Documentation 3.0
  • Setting up the CloudIO platform
    • Platform Installation
      • Pre-requisites
      • Configuring the database
        • Configuring the Oracle database
        • Configuring the MySQL database
      • Installing JDK
      • Installing the servers
        • Installing and configuring the Tomcat server
        • Installing and configuring the JBoss (WildFly) server
          • Setting up the JBOSS server
          • Deploying the WAR file
      • Setting up the Worker/Apache cluster
        • Setting up the essentials as a non-ROOT user
          • Installing the Tomcat connectors
          • Installing the Tomcat native library
          • Configuring the setup
      • Launching the installer
      • Installing the CloudIO platform
      • Performing post-installation activities
      • Signing in to the CloudIO platform
      • Signing out of the CloudIO platform
      • Working with the Setup page
        • Using additional connections
      • Setting up live connectors
      • Setting up the Active Directory
        • Syncing roles
      • Setting up Instance Types
      • Setting up Security Best Practices
  • Building your first application
    • Building Your First Application
      • Understanding the use case
      • Creating tables
      • Creating datasources
        • Defining attribute properties
        • Assigning roles to a datasource
      • Creating pages
        • Designing the user interface
          • Adding components to the lookup page
          • Adding components to the ticket summary page
          • Adding components to a new ticket page
      • Viewing the final output
  • Understanding the user interface
    • Understanding the User Interface
      • Working with the menu bar
      • Managing user preferences
        • Changing password
      • Working with navigation menu
      • Working with the developer group of the developer role
      • Working with other developer role groups
      • Managing Profiles
  • Working with roles and users
    • Working With Roles And Users
      • Defining a role
      • Understanding the types of roles
      • Creating a user
        • Assigning a role to the user
      • Managing roles and users
  • WORKING WITH DATASOURCES
    • Working with DataSources
      • Understanding the CloudIO data sources
      • Accessing data sources
      • Creating a data source
        • Defining data source details
        • Defining attribute properties
        • Defining a Pre Query
          • Examples of pre-query scripts
          • Pre-query variables
        • Defining a Post Query
          • Passing data from pre-query to post query
        • Defining server side validations
          • Validation sequence
          • Adding conditional defaulting rules
        • Assigning roles to a data source
        • Defining email actions
        • Performing DML operations using stored procedures
          • VALIDATE_ROW procedure
          • POST_QUERY procedure
      • Generating a data source
      • Managing datasources
      • Accessing data sources using REST API
        • Understanding CloudIO REST APIs
        • Authentication
        • Error handling
        • Performing query operations
        • CloudIO REST API playground
  • WORKING WITH PAGES
    • Working with Pages
      • Understanding pages and their types
      • Creating a page
      • Editing a page
        • Managing the version history of the page
      • Working with page components
        • Understanding the components panel
        • Understanding the components of a page
        • Understanding the standard properties of components
      • Working with data stores
        • Adding a data store to a page
        • Defining data store properties
        • Defining triggers and actions for a data store
  • WORKING WITH PATCHES
    • Working with Patches
      • Understanding patches
      • Preparing a datasource patch
      • Preparing a page patch
      • Preparing a role patch
        • Preparing a patch for multiple roles
      • Downloading a patch
      • Uploading a patch
      • Deleting patches
  • Working with additional functionality
    • Working with Additional Functionality
      • Using data sources for advanced functions
        • Adding custom handlers
          • List of methods in ObjectHandler interface
          • Sample code to override the handlerAfterInsertRow method
          • Uploading the compiled Java class
        • Managing activity streams
      • Accessing pages from Oracle EBS
        • Configuring Oracle EBS
        • Configuring CloudIO
      • Customizing the page using CSS
      • Creating PDF documents using MagicBox
        • Understanding widgets
      • Utility methods
      • Generating the output based on a docx template
      • Audit features
  • UI Components
    • Widgets
      • Action Button
      • Aggregate Card
      • Attachment Column
      • Attachment Dropzone
      • Attachment Upload
      • Attribute
      • Auto Breadcrumb
      • Badge
      • Barcode Scanner
      • Bing Map
      • Bing Map Navigator
      • Breadcrumb
      • Breadcrumb Item
      • Button
      • Button Dropdown
      • Button Group
      • Calculated Column
      • Calculated Number Column
      • Calculated String Column
      • Calendar
      • Calendar Heatmap
      • Capture Image
      • Card Body
      • Card Footer
      • Card Header
      • Card Header Icon
      • Card Table
      • Card Table Column
      • Card Table Row Selection
      • Card Wrapper
      • Carousel
      • Case
      • Change Role
      • Char Circle
      • Chart
      • Chart
      • CheckBox
      • Checkbox Column
      • Checkbox Column
      • Col
      • Collaboration
      • Color
      • Color Formatter
      • Color Range
      • Color Select
      • Combination Chart
      • Connection Popover
      • Custom Renderer Column
      • DIV
      • Data Column
      • Data Store
      • DataList
      • Date
      • Date Column
      • Date Column
      • Date Column
      • Date Field
      • Date Search Field
      • Device Popover
      • Drag Source Wrapper
      • Drop Target Wrapper
      • Dynamic Formula Number Column
      • Dynamic Formula String Column
      • EmbedPage
      • Extra Large View
      • Footer
      • Form
      • Form Search
      • Fusion Chart
      • Gantt Chart
      • Gauges
      • Google Drive Attachment Column
      • Google Drive Attachment Dropzone
      • Google Map
      • Google Navigator
      • Grid
      • Grid Child
      • Grid Layout
      • Grid Personalization Menu
      • Gridster Layout
      • Gridster Personalization Menu
      • Group Filter
      • H1
      • H2
      • H3
      • H4
      • H5
      • HTML
      • Handle
      • Heat Map Chart
      • Hidden Column
      • Horizontal Layout
      • Horizontal Section
      • IFrame
      • IOT Canvas
      • IOT Device Drag Source
      • Icon
      • Icon Column
      • Icon Column
      • Icon Menu
      • Icon Select
      • Image
      • Image Cropper
      • Info Box
      • InfoWindow
      • Input
      • Input
      • Kanban Board
      • Kanban Column
      • LOV
      • Large View
      • Lov Column
      • Mapping
      • Mapping
      • Medium View
      • Mirror
      • Monaco Editor
      • Multi Field
      • Multi Level Pie Chart
      • Multi Select LOV
      • Multi Series Chart
      • Node Graph
      • Number
      • Number Column
      • Number Column
      • Number Column
      • Number Field
      • Number Search Field
      • OCR Component
      • Order By Param
      • Organization Chart
      • Output
      • Page
      • Page Fragment
      • Pagination
      • Paragraph
      • Password Field
      • PivotGrid
      • Pointer
      • Popover
      • Popup
      • Progress
      • Progress Bar
      • Progress Bar Color
      • Progress Column
      • Pulse
      • Pulse
      • Query Additional Datasource
      • Query Param
      • Query Param Indicator Icon
      • Quick Filter
      • Quick Filter Attribute
      • RadioBox
      • Rich Text Editor
      • Row
      • Row Action
      • Row Col Column
      • Row Number Column
      • Row Selection Column
      • Row Selection Column
      • Saved Search Menu
      • Scanner Field
      • Scroll Layout
      • Search Attribute
      • Select
      • Select Column
      • Select Column
      • Set Data
      • Set URL Param
      • Sheet Data
      • Side Tab Item
      • Side Tab Panel
      • Signature Pad
      • Simple Alert
      • Slide Toggle
      • Slide Toggle Column
      • Slider
      • Small View
      • Smart Search
      • Smart Search Filter
      • Source Query Param
      • Star Rating
      • String Column
      • String Column
      • String Column
      • Summary
      • Switch
      • Switch Column
      • Switch Column Case
      • Tab Item
      • Tab Panel
      • Tab Panel Control
      • Table
      • Tags Input
      • Text Field
      • Thumbnail
      • Timeline
      • Transaction
      • Tree Column
      • UIView
      • URL Param
      • User Pic Column
      • User Picture
      • Vertical Layout Panel
      • Vertical Section
      • Video
      • Video Recorder
      • Watch
      • Wave
      • Wave Column
      • Wizard Step
      • Wizard Steps
      • Workflow Viewer
      • XY Chart
      • ZoomLine Chart
    • Triggers
      • Trigger After Device Drag
      • Trigger After Device Move
      • Trigger Before Device Drag
      • Trigger Before Device Move
      • Trigger After Delete Record
      • Trigger After Drop
      • Trigger After Insert StoreRecord
      • Trigger After Popup Close
      • Trigger After Popup Open
      • Trigger After Query
      • Trigger After Save
      • Trigger After Save
      • Trigger After Select Query
      • Trigger After Update StoreRecord
      • Trigger After Upload Attachment
      • Trigger Before Create
      • Trigger Before Delete StoreRecord
      • Trigger Before Drop
      • Trigger Before Edit Cell
      • Trigger Before Insert StoreRecord
      • Trigger Before Popup Close
      • Trigger Before Popup Open
      • Trigger Before Query
      • Trigger Before Query
      • Trigger Before Record Change
      • Trigger Before Render
      • Trigger Before Save
      • Trigger Before Save
      • Trigger Before Select Query
      • Trigger Before Update StoreRecord
      • Trigger Before Upload Attachment
      • Trigger On Aggregate Click
      • Trigger On Any Attribute Change
      • Trigger On Attribute Change
      • Trigger On Cell Click
      • Trigger On Change
      • Trigger On Click
      • Trigger On DataStore State Change
      • Trigger On Day Click
      • Trigger On Device Click
      • Trigger On Device Hover
      • Trigger On Dismiss
      • Trigger On Drag
      • Trigger On Drag End
      • Trigger On Drag Start
      • Trigger On Drop
      • Trigger On Enter Key Press
      • Trigger On Event Click
      • Trigger On Event Drop
      • Trigger On Event Resize
      • Trigger On First Visit
      • Trigger On Key Press
      • Trigger On Mouse Over
      • Trigger On No Data Action Button Click
      • Trigger On Page Active
      • Trigger On Page Exit
      • Trigger On Page Init
      • Trigger On Page Switch
      • Trigger On Record Active
      • Trigger On Row Click
      • Trigger On Row Selection Change
      • Trigger On Scan
      • Trigger On Tab Active
      • TriggerOnCellDoubleClick
      • TriggerOnRowDoubleClick
    • Actions
      • Abort
      • Abort If DataStore Is Empty
      • Action Copy
      • Action Download Attachment
      • Action Group
      • Action Search
      • Add Breadcrumb Item
      • Add Connection
      • Add Smart Search Filters
      • Add Smart Search Filters From Aggregate
      • After Duplicate Transaction StoreRecord
      • Case
      • Change Language
      • Choose Attachment
      • Clear All Filters
      • Clear All Query Params
      • Clear All StoreRecord Messages
      • Clear DataSource
      • Clear Grid Sort
      • Clear Query Param
      • Clear Smart Search Filters
      • Clear StoreRecord Message
      • Confirm Message
      • Copy StoreRecord
      • Copy StoreRecord In Loop
      • Delete Current Record
      • Delete Selected Records
      • Delete StoreRecord In Loop
      • Deselect All Records
      • Deselect StoreRecord
      • Drag Drop Operation
      • Duplicate Item
      • Duplicate StoreRecord
      • Duplicate Transaction
      • Eval And Execute Expression
      • Export Data
      • Export To Google Sheet
      • Geo Location
      • Go Back
      • Go To First Field
      • Go To First Record
      • Go To Item
      • Go To Last Record
      • Go To Next Record
      • Go To Page
      • Go To Previous Record
      • Hide Item
      • Hide Popup
      • Import Data
      • Insert Record
      • Invoke DataSource
      • Invoke Trigger
      • Loop
      • Loop Records
      • Multi Sheet Export
      • Open URL
      • Print Props To Console
      • Print To Console
      • Query DataSource
      • Query DataSource From Aggregate
      • Reduce
      • Refresh DataSource
      • Refresh Navigation Menu
      • Register State
      • Remove Connection
      • Reset DataStore
      • Reset StoreRecord
      • Save DataSource
      • Save Transaction
      • Save Video Recording
      • Select All Records
      • Select StoreRecord
      • Server Validate
      • Set As Current StoreRecord
      • Set Default Value
      • Set Message On StoreRecord
      • Set Property
      • Set Query Filter Value
      • Set Select Attributes
      • Set Value
      • Show Item
      • Show Message
      • Show Popup
      • Silent Sign Out
      • Start Video Recording
      • Stop Video Recording
      • Switch
      • Update Item Number Property
      • Update Item String Property
      • Update StoreRecord
      • Update StoreRecord In Loop
      • Wait
      • Wait For LOV
Powered by GitBook
On this page

Was this helpful?

  1. WORKING WITH DATASOURCES
  2. Working with DataSources
  3. Creating a data source
  4. Defining a Pre Query

Examples of pre-query scripts

  1. The manipulation of the WHERE clause of a Search. The platform appends the result of this query to the result of the generated whereClause.

// check if whereClause already exists
if (whereClause.length() > 0) {
    // whereClause already exists. append AND or OR clause as required
    whereClause.append(" AND ");
}
// use bind variables. e.g. ? or :EVENT_STATUS
whereClause.append("x.EVENT_STATUS = ?");
// append the bind variable
params.add(101);

2. Advanced manipulation of the WHERE clause

String custNo = data.get("accountNumber");
// check if the custNo is entered by the user in the search region
if (custNo != null) {
    if (whereClause.length() > 0) {
        whereClause.append(" AND ");
    }
    if (custNo.indexOf("%") != -1) {
        // wildchar found, use LIKE instea
        whereClause.append("X.ACCOUNT_NUMBER LIKE ?");
    } else {
        whereClause.append("X.ACCOUNT_NUMBER = ?");
    }
    params.add(custNo);
}

3. Calling a PL/SQL procedure before executing the query

/ Get the required parameter values from the current search criteria
// provided by the user i.e. user entered values in the search panel
String customerNameDummy = data.get("partyName");
String customerNumberDummy = data.get("accountNumber");
String contactNameDummy = data.get("contactName");
String emailDummy = data.get("emailAddress");
String postalCodeDummy = data.get("postalCode");

// Prepare the model to be used invoke the Pre-Query PL/SQL Procedure
RPCModelData model = new RPCModelData();
model.set("customerName", customerNameDummy);
model.set("customerNumber", customerNumberDummy);
model.set("contactName", contactNameDummy);
model.set("contactEmail", emailDummy);
model.set("postalCode", postalCodeDummy);
model.set("searchCriteria", searchValue);
// Invoke the Pre-Query PL/SQL Procedure. This will call
// PACKAGE.INSERT_ROW Procedure
db.postObjectToDB("customerPreQueryAPI", model);
// Get the return value
Double searchValue = model.get("searchCriteria");
// Use the return value in the where clause
if (searchValue != null) {
    if (whereClause.length() > 0) {
        whereClause.append(" AND ");
    }
    whereClause.append("x.search_context_id = ? ");
    params.add(searchValue);
}

4. The manipulation of the ORDER BY clause of a search. The platform appends the result of this query to the result of the generated order by clause.

if (orderByClause.length() > 0) {
  orderByClause.append(", ");
}
orderByClause.append("x.NET_LOSS_AMOUNT");

5. Replacing the FROM clause of a query

if (someCondition) {
fromClause.setLength(0); // remove the existing FROM CLAUSE
fromClause.append(" FROM NEW_TABLE_OR_VIEW_NAME x"); // alias should always be x
}

6. Manipulating the bind variable

// make sure to uncheck the "Query Allowed" property for this attribute
// so that the system won't include this attr in the system generated
// where clause
String phoneNo = data.get("phoneNumber");
if (phoneNo != null) {
    if (whereClause.length() > 0) {
        whereClause.append(" AND ");
    }
    whereClause.append("x.transposed_phone_number LIKE ?");
    params.add(new StringBuilder(phoneNo.replaceAll("[^0-9]", "")).reverse().append("%").toString());
}

7. Replacing the query with a custom query with UNIONs

Double custAccountId = data.get("customerId");
if (custAccountId != null) {
    // backup the existing bind variables if any as we need the repeat
    // the where clause of every UNION
    List paramsCopy = new ArrayList();
    paramsCopy.addAll(params);
    StringBuffer newWhereClause = new StringBuffer();
    if (whereClause.length() > 0) {
        newWhereClause.append(" AND ");
    }
    // backup the select clause as we need to repeat for every UNION
    String sel = selectClause.toString();
    newWhereClause.append("x.bill_customer_id = ?");
    /**
     ** RA_TOTAL_ROWS will help the platform to know the total rows
     * thereby avoiding the use of an extra query to calculate the total
     * rows i.e. select count(1)
     **/
    fullSQL.append("SELECT X.*, count(1) over() RA_TOTAL_ROWS FROM (");
    fullSQL.append(sel).append(fromClause).append(" WHERE ").append(whereClause).append(newWhereClause);
    params.add(custAccountId);
    fullSQL.append(" UNION ");
    newWhereClause.setLength(0);
    if (whereClause.length() > 0) {
        newWhereClause.append(" AND ");
    }
    newWhereClause.append("x.ship_customer_id = ?");
    fullSQL.append(sel).append(fromClause).append("WHERE ").append(whereClause).append(newWhereClause);
    params.addAll(paramsCopy);
    params.add(custAccountId);
    fullSQL.append(" UNION ");
    newWhereClause.setLength(0);
    if (whereClause.length() > 0) {
        newWhereClause.append(" AND ");
    }
    newWhereClause.append("x.customer_id = ?");
    fullSQL.append(sel).append(fromClause).append("WHERE ").append(whereClause).append(newWhereClause);
    params.addAll(paramsCopy);
    params.add(custAccountId);
    fullSQL.append(") X");
    if (orderByClause.length() > 0) {
        fullSQL.append(" ORDER BY ").append(orderByClause.toString().toLowerCase().replaceAll("_", ""));
    }
}

8. Restricting blind query by appending the following code at the end of the pre-query script

if (whereClause.length() == 0) {
  throw new RAException("Blind Query", "You must specify atleast one search criteria");
}

10. Custom handling of grid filters

import com.extjs.gxt.ui.client.data.FilterConfig;

List<filterconfig> filterConfigs = data.getFilterConfigs();
if (filterConfigs != null) {
    for (FilterConfig filter : filterConfigs) {
      if ("item".equals(filter.getField()) && filter.getValue() != null) {
        whereClause.append(" AND x.ITEM LIKE ?");
        params.add(((String) filter.getValue()).toUpperCase() + "%");
      }
    }
}

11. Range query

Date from = data.get("dateFrom");
Date to = data.get("dateTo");
if (from != null) {
    // check if whereClause already exists
    if (whereClause.length() > 0) {
        // whereClause already exists. append AND or OR clause as
        // required
        whereClause.append(" AND ");
    }
    // use bind variables. e.g. ? or :EVENT_STATUS
    whereClause.append("x.ORDER_DATE >= ?");
    // append the bind variable
    params.add(from);
}
if (to != null) {
    if (whereClause.length() > 0) {
        whereClause.append(" AND ");
    }
    whereClause.append("x.ORDER_DATE <= ?");
    params.add(to);
}

12. Query by name

The following pre-query script shows a simple approach for performing search:

boolean showAll = "Y".equals(db.getProfile("SHOW_ALL_ACTIVITIES"));
// from a given customer... show all activities for that customer
if (whereClause.indexOf("CUST_ACCOUNT_ID") == -1) {
    String group = data.get("groupCode");
    String dueBy = data.get("dueBy");

    if ("MY".equals(group)) {
        if (whereClause.length() > 0) {
            whereClause.append(" AND ");
        }
        whereClause.append("x.OWNER_ID = ?");
        params.add(userId);
    } else if ("ME".equals(group)) {
        if (whereClause.length() > 0) {
            whereClause.append(" AND ");
        }
        whereClause.append("x.CREATED_BY = ?");
        params.add(userId);
    }

    if (data.get("creationDate") != null) {
        if (whereClause.length() > 0) {
            whereClause.append(" AND ");
        }
        whereClause.append("x.CREATION_DATE > ?");
        params.add(data.get("creationDate"));
    }
    Date fromDate = new Date();
    Calendar c = Calendar.getInstance();
    c.setTime(fromDate);
    c.roll(Calendar.DATE, false);
    fromDate = dateUtils.getEnd(c.getTime());
    Date toDate = dateUtils.getEnd(new Date());
    Date yestDate = dateUtils.getStart(new Date());

    String statusCode = "Closed";
    if (dueBy != null) {
        if (whereClause.length() > 0) {
            whereClause.append(" AND ");
        }
        if ("YESTERDAY".equals(dueBy)) {
            whereClause.append(" x.status_code != ? AND x.PLANNED_END_DATE < ?");
            params.add(statusCode);
            params.add(yestDate);
        } else {
            whereClause.append("x.PLANNED_END_DATE > ? AND x.PLANNED_END_DATE < ?");
        }
        if ("TODAY".equals(dueBy)) {
            params.add(fromDate);
            params.add(toDate);
        } else if ("TOMORROW".equals(dueBy)) {
            c.setTime(fromDate);
            c.roll(Calendar.DATE, true);
            fromDate = c.getTime();
            params.add(fromDate);
            c.setTime(toDate);
            c.roll(Calendar.DATE, true);
            toDate = c.getTime();
            params.add(toDate);
        } else if ("THIS WEEK".equals(dueBy)) {
            c.setTime(fromDate);
            c.add(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() - c.get(Calendar.DAY_OF_WEEK));
            fromDate = c.getTime();
            params.add(fromDate);
            c.add(Calendar.DAY_OF_YEAR, 7);
            toDate = c.getTime();
            params.add(toDate);
        } else if ("NEXT WEEK".equals(dueBy)) {
            c.setTime(fromDate);
            c.add(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() - c.get(Calendar.DAY_OF_WEEK));
            c.add(Calendar.DAY_OF_YEAR, 7);
            fromDate = c.getTime();
            params.add(fromDate);
            c.add(Calendar.DAY_OF_YEAR, 7);
            toDate = c.getTime();
            params.add(toDate);
        }
    }

    if (!showAll) {
        if (whereClause.length() > 0) {
            whereClause.append(" AND ");
        }
        whereClause
                .append("(x.GROUP_ID IN (SELECT G.GROUP_ID FROM JTF_RS_GROUP_MEMBERS M, JTF_RS_GROUPS_B G, jtf_rs_roles_vl RL, jtf_rs_role_relations RR")
                .append(" WHERE M.GROUP_ID = G.GROUP_ID AND G.START_DATE_ACTIVE < SYSDATE AND NVL(G.END_DATE_ACTIVE, SYSDATE+1) > SYSDATE AND G.ATTRIBUTE1 = 'Y' AND M.DELETE_FLAG = 'N' AND RR.ROLE_ID = RL.ROLE_ID AND RR.role_resource_type = 'RS_GROUP_MEMBER' AND RR.delete_flag = 'N' AND M.RESOURCE_ID = ?")
                .append(" AND RR.ROLE_RESOURCE_ID = M.GROUP_MEMBER_ID AND RL.ROLE_CODE = 'GWT_MANAGER')")
                .append(" OR x.GROUP_ID IN (SELECT G.GROUP_ID FROM JTF_RS_GROUP_MEMBERS M, JTF_RS_GROUPS_B G WHERE M.GROUP_ID = G.GROUP_ID AND G.ATTRIBUTE1 = 'Y' AND G.ATTRIBUTE2 = 'Y' AND M.RESOURCE_ID = ?)")
                .append(" OR x.OWNER_ID = ? OR x.CREATED_BY = ?")
                .append(" OR EXISTS (SELECT 1 FROM xxdaz_mace_subscriptions XMS WHERE  XMS.USER_ID = ? AND XMS.ACTIVITY_ID = X.ACTIVITY_ID AND XMS.SUBSCRIBED_FLAG = 'Y'))");
        params.add(db.getUserSession().getResourceId());
        params.add(db.getUserSession().getResourceId());
        params.add(userId);
        params.add(userId);
        params.add(userId);
    }
}
PreviousDefining a Pre QueryNextPre-query variables

Last updated 4 years ago

Was this helpful?

9. Query allowed By default, all attributes are query allowed and the platform automatically generates whereClause when a user perform a search on an attribute. To programmatically control the whereClause, uncheck the Query Allowed property while to ignore those attributes while generating the whereClause.

You can access the data related to the grid filters through object. You can usedata.getFilterConfigs() method to retrieve the list of FilterConfig.

By default, platform generates range search fields in a simple search panel for all date and number attributes. For custom search panel, while , you can define calculated from and to attributes with Select and Query Allowed unchecked. This will limit the range for search values.

defining the attribute properties
FilterConfig
defining the attribute properties