The following methods are available in "db" object that's available in Pre-Query, Post-Query, Server Side Validation Scripts, Object Handlers etc.

List<RPCModelData> assignRoles(String userName, String[] roleCodes)

This method can be used to assign roles to a user. You can use this method to assign multiple roles by passing role codes.
String userName = db.getSessionValue("username");
List<RPCModelData> userRolesList = db.assignRoles(userName, new String[]{"ordermanagement"});
RPCModelData cacheGetObjectsByNameValues(String ds, String attr,Object... nameValues)

This method can be used whenever you want to return RPC model data from database and cache it. Instead of querying databse every time, It will query once and store values in the cache. The subsequent calls will fetch from the cache instead of querying the database. Dont cache the data which changes frequently.
Double rsrcId = data.get("rsrcid");
RPCModelData resource = db.cacheGetObjectByNameValues("OJResources","rsrcid",rsrcId);
String rsrcName = resource.get("name");
String isIntenal = resource.get("isinternal");
String cleanHtml(String html)
RPCModelData createUser(String userName, String email,String DisplayName)

To create a new user. If the application being built requires to create a user to login into the application, then this method can be used.
RPCModelData userData = db.createUser("tonychou","tonyc@gmail.com","Tony Chou");
RPCModelData createUser(String userName, String email,String DisplayName, String managerName)
Map<String,Object> dbItemToClientItem(RPCModelData row)
Object evaluateSelectSQL(String sql)

This can be used when the user wants to execute a SQL query without any platform specific syntax. This is a plain SQL query excecution, and will not do any automatic conversion on result data. User has to take care of casting the result data based on what he is expecting from the query.
 double empId = 2001;
String empName = (String) db.evaluateSelectSQL("select emp_name from employee where emp_id = "
+ empId);
List<RPCModelData> executeQuery(String sql, Object[] params)

This method can be used to execute adhoc SQL statements with bind variables.
Double empId = data.get("empId");
List<RPCModelData> rows = db.executeQuery("SELECT EMP_NAME empName, DOB, EMP_NO empNo FROM EMP WHERE EMP_ID = ?", new Object[]{ empId });
if (rows.size() > 0) {
RPCModelData firstRow = rows.get(0);
String empName = firstRow.get("empName"); // use the column alias without an underscore
Date dob = firstRow.get("dob");
Double empNo = firstRow.get("empNo"); // all numbers are converted to Double
}
Note: Every column with underscore should have an alias without underscore.
String getChangesTextForStreamBody(RPCModelData data)
String getChangesTextForStreamBody(String attributesList, RPCModelData data, RPCModelData dbRow)
void setData(String key, Object value)

You can use this method to cache obects, primitive values and retrive the objects back whenever you require. These values are accessible in Pre-Query, Post-Query, and Server side validation scripts. You can use this method to store any global values.

ex.1: Store primitive values
db.setData("Is_Dev_Mode_On","Y");
ex.2: Store objects
RPCModelData appSession = new RPCModelData();
appSession.set("appId",1020);
appSession.set("isOAuth","Y");
db.setData("appsettings",appSession);
ex.3: You can also store list of rpc models which are queried from database.
String datasource = "employee";
Map<String,Object> map = new HashMap<String,Object>();
map.put("location","Madison");
int offset = 0;
List<RPCModelData> rows = db.getObjectsByNameValues(datasource,map,offset);
db.setData("emp_by_location_list",rows);

Object getData(String key)

This method is to retrive the stored objects, primitive values from the cache.
String isDevMode = (String)db.getData("Is_Dev_Mode_On");
List<RPCModelData> empList = (List<RPCModelData>)db.getData("emp_by_location_list");
Double getDBNextVal(String sequenceName)

This method is to get next value for any sequence.
 Double nextValue = db.getDBNextVal("XXRA_MASTER_S");

String getDiffHtml(RPCModelData data)
String getDiffHtml(String oldValue, String newValue)
String getDiffHtml(String oldValue, String newValue, int maxLength)
String getLink(boolean embeded, String linkName, String pageCode, String otherParams)
String getLink(boolean embeded,String linkName, String pageCode, String ds, String attr, String cond, Object value)
String getLink(boolean embeded, String linkName, String pageCode, String ds, String attr, String cond, Object value, String attr2, String cond2, Object value2)
String getLink(String linkName, String pageCode, String otherParams)
String getLink(String linkName, String pageCode, String ds, String attr, String cond, Object value)
String getLink(String linkName, String pageCode, String ds, String attr, String cond, Object value, String attr2, String cond2, Object value2)
String getNextVal(String sequenceName)
RPCModelData getObjectByNameValues(String ds, Object... nameValues)

To get a single RPC model by passing name, values and datasource. This method can be used when you want get a row from the database. This method is very handy as you need not construct whereClause, just need to pass the attributeName and attributeValues. Based on the passes attributes and value, it will construct the whereClause and query the table.
String datasource = "employee";
RPCModelData row = db.getObjectByNameValues(datasource,"ename","Rob Benada","location","madison");

List<RPCModelData> getObjectsByNameValues(String ds, int offset, Object... nameValues)

Same as above but to get a list of RPC Models.
String datasource = "employee";
int offset = 0;
RPCModelData row = db.getObjectsByNameValues(datasource,offset,"location","madison");
RPCModelData getObjectByPKValues(String ds, Object... params)

This method will return single RPC model data from the database based on passed primary key values. If you have list of primary keys and want to fetch the data from table then you can use this method. No need to pass the attribute names, just pass the value and platform will do the rest.

ex.1: if employee table has one primary key username
String datasource = "employee";
RPCModelData row = db.getObjectByPKValues(datasource,"robbenada");
ex.2: if employee table has compsite key with email and username
String datasource = "employee";
RPCModelData row = db.getObjectByPKValues(datasource,"rob@gmail.com","robbenada");
List<PCModelData> getObjects(String ds, String whereClause, List params)

This can be used when you want to get the list of RPC models form the databse by passing the datasource, where clause and list of params. This method will provide a way to construct the where clause which will give you more options to query the required data.

 StringBuilder empIdsString = new StringBuilder();
Integer[] empIds = new Integer[]{1001,1002,1003,104};

List params = new ArrayList();
for (int i=0; i<empIds.length; i++) {
if (empIds[i] == null || "null".equals(empIds[i]) || "".equals(empIds[i])) {
continue;
}
if (i > 0) {
empIdsString.append(", ");
}
empIdsString.append("?");
params.add(new Double(empIds[i]));
}

String whereClause = "#empId# IN ("+empIdsString.toString()+")";
//where #empId# attribute name should always enclosed with #
List<RPCModelData> list = db.getObjects("Employee",whereClause, params);
RPCModelData getObjectByNameValues(String ds, Map<String,Object> map, int offset)

Another variant to fetch data from the table. You can set the attribute names and values as key value pairs in a map and pass it. You can specify the offset value as 0.
 String datasource = "employee";
Map<String,Object> map = new HashMap<String,Object>();
map.put("ename","Rob Benada");
map.put("location","Madison");
int offset = 0;
RPCModelData row = db.getObjectByNameValues(datasource,map,offset);
List<RPCModelData> getObjectsByNameValues(String ds, Map<String,Object> map, int offset, int limit)

This is also an overloaded method for getting list of data objects (rpc models) from the table by passing attributeNames, attributeValues as a Map. You can pass the offset and limit to get the paginated result back.
 String datasource = "employee";
Map<String,Object> map = new HashMap<String,Object>();
map.put("location","Madison");
int offset = 0;
int limit = 200;
RPCModelData row = db.getObjectByNameValues(datasource,map,offset,limit);
List<RPCModelData> getObjectsByNameValues(String ds, Map<String,Object> map, int offset)

To get list of rpc models by using attributeName,attributeValue in a Map.
 String datasource = "employee";
Map<String,Object> map = new HashMap<String,Object>();
map.put("location","Madison");
int offset = 0;
List<RPCModelData> rows = db.getObjectsByNameValues(datasource,map,offset);
String getRoleEmails(String roleName)

This method can be used to get all the user's email addresses under a specific role. Pass the role name as arugment. This method will return all the email addresses as a string with comma separated values.

String emailAddressesWithCommaSeparatedValues = db.getRoleEmails("Manager");
Void setSessionData(String key, Object value)

This method can be used to set temporary values which can be accessed in Pre-Query, Post-Query and Server side validations scripts.
ex.1: settting prmitive values
db.setSessionData("customerid",1200);
ex.2: setting objects into session
RPCModelData newemployee = new RPCModelData();
newemployee.set("ename","Tony Chou");
newemployee.set("location","California");
db.setSessionData("custemployee",newemployee);

Note: Telidos Platform is stateless and hence any session data set is not guaranteed to be available accross requests. This method is primarily intended to share data between Pre-Query & Post-Query or between Server Side Validation Scripts within the same transaction.
Object getSessionData(String key)

This mehtod can be used to access the values which are set using setSessionData() method.
String customerId = db.getSessionData("customerid");
Object getSessionValue(String fieldName)

Use this method to access the implicity session attributes like clienttimezon, username, userid, displayname, domainname. etc.
String timezone  =  db.getSessionValue("clienttimezone");
String getURL()
String getURL(boolean embeded, String pageCode, String otherParams)
String getURL(String pageCode, String otherParams)
String getUserDisplayName(java.lang.Double userId)

To get display name of a logged in user.
 String displayName = db.getUserDisplayName(userid); 
// where userid is implicit variable which is available in the scriptUtil (db)
String getUserEmailAddress(java.lang.Double userId)

To get the email of a logged in user.
 String emailAddress = db.getUserEmail(userid); 
// where userid is implicit variable which is available in the scriptUtil (db)
String getUserUserName(Double userId)

To get the user name for any user by passing userid.
double otherUserId = 10001;
String userName = db.getUserUserName(otherUserId);
boolean isObjectExists(String ds, Map<String,Object> map)

This method can be used to check if the specific data row is exist in the database table or not. It will take the datasource name and keys(attributeNames) and values(attributeValues) as arguments and return boolean type. i.e true or false
Map<String,Object> map = new HashMap<String,Object>();
map.put("empId","10021");
boolean isExistRow = db.isObjectExists("employee",map);
void performFTPActions(String hostName, String uName, String pwd, Double fileId, String destFolder, String action)
RPCModelData postObjectToDB(String ds, RPCModelData data)

This method can be used to insert a RPC Model object into datasource. You can use this method to post data into to the table from Pre-Query,Post-Query and Server side validation scripts. You need to construct a RPCModelData with keys(attributeNames) and values (attributeValues) and pass to the method along with datasource name.
 RPCModelData employee = new RPCModelData();
employee.set("ename","Bob Thomas");
employee.set("location","New York");
employee.set("age",36);

String ds = "employee";
RPCModelData result = db.postObjectToDB(ds, employee);
List<RPCModelData> postObjectsToDB(String ds, List<RPCModelData> data)

This is a overloaded method to insert multiple rows into the table.
 List<RPCModelData> empList = new ArrayList<RPCModelData>();
RPCModelData employee = new RPCModelData();
employee.set("ename","Rob Benada");
employee.set("location","Madison");
employee.set("age",58);
empList.add(employee);

employee = new RPCModelData();
employee.set("ename","Jeff Kirk");
employee.set("location","Madison");
employee.set("age",48);
empList.add(employee);

String ds = "employee";
List<RPCModelData> result = db.postObjectsToDB(ds, empList);

void publishSystemNotification(String subject, String body, String roleIds,String userIds)

To publish notifications as ADMIN. This is basically to insert notifications into notification tables programatically. You can also add notificationsmanually using the Platform screen 'Notifications' under Developer Menu. You can pass the role id's as comma separated string.
Date commentedDate = data.get("commenteddate");
String commentedBy = db.getSessionValue("displayname");

StringBuilder post = new StringBuilder();
post.append("<b>"+commentedBy+" Commented on the current task on "+commentedDate+"</br>");
post.append(comments);

db.publishSystemNotification("New note",post.toString(),"1001,2005",null);
void publishUserNotification(String subject, String body, String roleIds, String userIds)

This is the overloadded method to publish notifications, here you can publish notifications as logged in user.
Date commentedDate = data.get("commenteddate");
String commentedBy = db.getSessionValue("displayname");
String roleId = "1001;2005";
String userId = "2098;4098";

StringBuilder post = new StringBuilder();
post.append("<b>"+commentedBy+" Commented on the current task on "+commentedDate+"</br>");
post.append(comments);


db.publishUserNotification("New Task Comment",post.toString(),roleId,userId);
void queueEmails(String es, String eb)
void sendEmail(String toEmails, String ccEmails, String es, String eb, String custTemplate)

This method can be used to send emails programatically. If custTemplate is set to 'N' then the platform default template is used.
db.sendEmail("jhon@yahoo.com,albert@gmail.com", null, subject, sb.toString(), "N"); // use comma separted values to send emails for multiple users.
void sendEmail(String toEmails, String ccEmails, String bccEmails,String es, String eb, String custTemplate)

This method can be used to send email out with bcc emails.
db.sendEmail("john@yahoo.com,albert@gmail.com", null, "kimberly@gmail.com", subject, sb.toString(), "N"); // use comma separted values to send emails for multiple users.
void sendEmail(String toEmails, String ccEmails, String es, String eb, Date startDate, String custTemplate)

This method can be used to send emails with start date. Using this you can queue up emails that needs to be sent out on a particular date.
Date d = new Date("12/12/2013");
db.sendEmail("john@yahoo.com,albert@gmail.com", null, subject, sb.toString(), "N"); // use comma separted values to send emails for multiple users.
void public void sendEmail(String toEmails, String ccEmails, String bccEmails, String es, String eb, String custTemplate,Long fileId)

This can be used for sending emails with single attachment.
Double fileId = data.get("attachmentId"); 
db.sendEmail("john@yahoo.com,albert@gmail.com", null, null,subject, sb.toString(), "N",fileId);
// where fileId is a reference of a file stored in RA_FILES.
void public void sendEmail(String toEmails, String ccEmails, String bccEmails, String es, String eb, String custTemplate,List<Long> fileIds)

This can be used for sending emails with multiple attachments.
Double fileId1 = 10002;
Doubel fileId2 = 10004;
List<Long> fileIds = new ArrayList<Long>();
fileIds.add(fileId1);
fileIds.add(fileId2);
db.sendEmail("john@yahoo.com,albert@gmail.com", null, null,subject, sb.toString(), "N",fileIds);
// where fileId is a reference of a file that is stored in RA_FILES.
java.util.Date trunc(Date date)
void public void confirmationMessageBox(String confirmationMessage,
String confirmationOptions, double confirmationSequence,
String confirmationToken, String cancelButtonText)
int executeUpdate(String sql, Object[] params) throws SQLException
Double executeQueryDouble( String sql, Object[] params) throws SQLException
Object executeQueryObject( String sql, Object[] params) throws SQLException
void setProfileValue(Double userId, String code, String value)
String getProfile(Double userId, String profileCode)
String getProfile(String profileCode)
String resetPassword(String userName, String emailAddress, boolean sendEmailAndNotification)

Location

101 California Street, Suite 2710
San Francisco, CA 94111


440 N. Wolfe Rd.
Sunnyvale, CA 94085


Office 11, 5th Floor, Building 9,
Mindspace IT Park
Hyderabad 500081

p: +1 (844) AT CloudIO (844-282-5683)
f: +1 (650) 300-5247 | e: sales@cloudio.io
© 2009, 2017 CloudIO Inc. | Terms of Use | Privacy Policy