DeXML Native Functions
This page contains some native functions which can be included in DeXML scripts for Deputy.
Assign
- Assign a value to a variable
- Define the scope at first time of assignment. If not given it will be assumed as local
- Index is only for array variable
- Local variables are reset when script leaves the current function stack
- Global variables are available across all functions
- Session variables remain available globally between function calls
- System variables are available for the whole system! These are stored in a persistant database and are not affected by logging in or out, between different users etc
- Please note that system variables do not allow some utility methods (eg. index_exists). You may want to fetch them separately
<assign var="name" scope="local [default] | global| session" [index="index"] [value="expression"] />
<assign var="name">
anything
</assign>
Atom
- Return an atom
<atom>I am an atom</atom>
<atom var="assigned_var_name" [scope="local | global | session"] [index="index"] [assign="varname"]/>
GetNested
Returns nested variable value from a multi-dimensional key-value array. If not found returns default value.
It is a lot faster to do the following
get_nested({var:"x.y.z", default:"10"})
as opposed to
if x
if x.y
if x.y.z return x.y.z
else return 10
else return 10
else return 10
DeXML example
<assign var="y"></assign>
<assign var="y" index="z" ><atom>10</atom></assign>
<assign var="x" index="y" ><atom var="y"/></assign>
<get_nested var="x.y.z" default="5" [assign="varname"]/>
You can also use getnested with a direct system look up by supplying _system and id parameter.
For example if you are given a Timesheet (variable shift) and you want to find out what should be the base payrate of the employee, you can do this using a single line command as follows:
get_nested({var:"Agreement.ContractObject.BasePayRuleObject.HourlyRate",default:"0" , system:"Employee",id:shift.Employee})
- This command will first look up Employee with the Timesheet Id.
- It will then look up for the EmployeeAgreement allocated to the employee.
- It will then look up the associated EmploymentContract by ContractObject and PayRules with the BasePayRuleObject to find the HourlyRate.
Del
- Delete an element in the array by index
<del var="array_var_name" [scope="local (default) | global | session"] index="index_id" />
IndexExists
- Return true or false about whether a index exists in an array
<index_exists var="array_var_name" [scope="local (default) | global | session"] index="index_id" />
Length
- Return length of a variable (preferably array)
<length var="var_name" [scope="local [default] | global | session"] assign_attribs/>
AddSlashes
- Add slashes to a variable and return it
<addslashes input="Input_String_or_Varname" assign_attribs/>
DatePrint
- Print a date from unixtimestamp or other kind of date strings
- It will return " IF it could not convert the input to appropriate format
- Supply timezone if you want to print the date to another timezone
<dateprint format="format_string" [input="timestamp_or_datestring"] [timezone="print_in_timezone"] assign_attrib/>
UnixTime
- Return unix timestamp given day, month, year, hour, minute, seconds
- If any of the parameters are not given, current times value is assumed
<unixtime [hour="hour"] [minute="minute"] [second="second"] [day="day"] [month="month"] [year="year"] assign_attrib/>
DateAdd
- Perform date arithmetic on given unix timestamp
<dateadd input="unixtimestamp" [hour="hour"] [minute="minute"] [second="second"] [day="day"] [month="month"] [year="year"] assign_attrib/>
TimeDiff
- Given two unix timestamps, return the difference between them in hours
- If either attributes are omitted, the current timestamp is assumed
<timediff [from="unixtimestamp"] [to="unixtimestamp"] assign_attrib/>
ScheduleOverlap
- Check if a period overlaps or a timestamp is contained in a existing schedule
- Given the id of an existing DeputecSchedule object and two or more timestamps
- Find out if the period overlaps the schedule or the timestamp is contained within the schedule. The department id is also an optional parameter so that the public holiday wrapper schedule can honour the holidays-departments association.
<schedule_overlap_type id="integer" from="unixtimestamp" to="unixtimestamp" [operational_unit="integer"] assign_attrib/>
OverlapType
- Find the overlap type between two time periods
- Given two time periods (schedule, input) find their overlap type in a way similar to how DeputecScehedule::doesOverlap does it. Return the overlap type as well as the period that can be defined by that, in a way similar to our pay condition suggestion algorithm.
<overlap_type schedule_start="unixtimestamp" schedule_end="unixtimestamp" input_start="unixtimestamp" input_end="unixtimestamp" assign_attrib/>
Sort
Sorting a given variable as with option given
- value: Sorts on the value of the array (DEFAULT)
- key: Sorts on the key
- natural: Natural language sorting (for the values a2, a10; value sorting returns a1, a10, a2; natural sorting will return a1, a2, a10)
- reverse: Reverses an array-No sorting
- random: Randomises the array. No sorting. Index is lost!
<sort var="array_variable" [with="value | key | natural | reverse | random"] assign_attrib/>
Sprintf
- Do Sprintf like C
- Must have a format argument. Everything else is processed as replacement.
<sprintf format="%s %s..." input1="$var1" input2="hello" assign_attribs />
Mustache
- Run mustache templating on given string with specified inputs
- Please note that you need to encode multiple variables into a single variable
- Partials can be anything as long as it is partial[0-9]* meaning either partial and anything after the partial
<mustache input="anything" [partial="partial" partial1="partial" partial2="partial" ...] assign_attribs>
Your template
</mustache>
Sample template where we get timesheets of an employee and show it through partials
<db_fetch system="Timesheet" assign="objTimesheetArray">
<db_condition>
<db_compare column="Employee" function="eq">
<atom>12</atom>
</db_compare>
</db_condition>
</db_fetch>
<assign var="input" index="objTimesheetArray"><atom var="objTimesheetArray"/></assign>
<assign var="input" index="sampleName">Austin Powers</assign>
<mustache input="\$input" partial="Id is {{Id}} Total time {{TotalTime}}" partial1="{{StartTime}}, {{EndTime}}" assign="ret" >
Timesheets for {{sampleName}}:
{{#objTimesheetArray}}
{{>partial}}
Times are {{>partial1}}
{{/objTimesheetArray}}
</mustache>
Base64
- Base64 encode or decode
<base64 [op="encode (default) | decode" ] input="var" assign_attribs />
Exit
- Exits with the given attribute
<exit [var="varname"]/>
If
- Evaluate IF statements. The format is as follows
<if [var="varname_which_canbe_true_false"]>
<condition>Conditional code that must return NON-null value. FALSE,0,NULL is considered false will goto elseifs/else</condition>
<perform>Code to be performed if all ok</perform>
<elseif>* (See elseif doc)
<else>Code to be performed if it fails</else>
</if>
ElseIf
- Evaluate ELSEIF statements. The format is as follows
<elseif [var="varname_which_canbe_true_false"]>
<condition>Conditional code that must return NON-null value. FALSE,0,NULL is considered false and return false</condition>
<perform>Code to be performed if all ok</perform>
</if>
Condition
- Eval conditional statements. The format is as follows
<condition [op="and|or"]> (Default is and)
<compare />
</if>
Function
- Process xslt function
<function [assign="varname] [scope="local | global | session"] assign_attributes>
XSLT FUNCTION DEF
</function>
Compare
- Compare two values with given condition
- If second parameter is not given and we are not doing the "NOT" function second param will be considered NULL
<compare function="eq|gt|lt|ge|le|nt|ne|and|or|bitand|bitor|xor|regex|in|notin" [value1="anyvalue"] [value2="anyvalue"] assign_attribs>
<anything1/>
<anything2/>
</compare>
Loop
- Loop through objects (array_variable) or keep looping for a given condition (while it is true)
<loop [var="array_variable"]>
[<condition /> ]
<perform />
</loop>
DbRecord
- Load a given object by its ID
<db_record system="SytemName" <!-- e.g Employee -->
id="12"
assignment_attributes />
DbFetch
- Fetch database records
- You can choose to get only the first row or even the first cell (first row specific column) -must specify the cell name
<db_fetch system="SytemName" <!-- e.g Employee -->
[fetch="first_row|cell|column"] [cell="columnname"] <!-- Get either the first row OR a cell -->
[aggr_func="Count|Sum|Minimum|Maximum|Avg" aggr_column="columnname"] [start=0] [max=0]
assignment_attributes >
<db_condition />
<db_sort />
<db_join />
<db_groupby />
<db_aggr />
<db_assoc />
</db_fetch>
DbCondition
- The format is as follows
<db_condition [op="and|or"]> (Default is and)
<db_condition/>
<db_compare />
</db_condition>
DbConditionUserSpecific
- Return a users specific permission clause
<db_condition_user_specific />
DbCompare
- Compare db data
- Please note that you need to manually join
<db_compare column="column_name" function="eq|gt|lt|ge|le|ne|regex|in|notin|like|notlike" [join=join_name]>
<anything/>
</db_compare>
DbDesc
- Return database schema information
<db_desc on="item" />
Will return all the database tables as an array Employee- or any other object name to get the array([fields]->array(field->type), [joins]->array(JoinName->SystemObjectName), [assocs]->array(AssociateName->SystemObjectName))
DbSort
- Process DB Sorting
<db_sort>
<db_sort_column order="asc">column_name</db_sort_column>
</db_sort>
DbSortColumn
- Process a DB sort column
<db_sort_column [order="asc|desc"] [join="joinObjectname"] >column_name</db_sort_column> <!-- Default order is asc -->
DbJoin
- Process DB Join
<db_join objname="CompanyObject"/>
DbAggr
- Process DB Aggr
<db_aggr field="Fieldname" func="function" />
DbGroup
- Process DB GroupBy
<db_groupby field="Fieldname"/>
DbAssoc
- Process DB Assoc
<db_assoc objname="CompanyObject"/>
Log
- Log messages. The messages are available in Show last output.
<log message="message" obj="" [system=0] />
RunJS
- Run custom JavaScript
- Note that JavaScript can only be run when server is evaluating client request for logged in user
- Kiosk/Cron will ignore this step
<runjs>alert('Yep! This is a javascript. You can put things inside CDATA if needed');</runjs>
RunScript
- Run another script and return its output. If you give dpInvoke=final it will only call the script once at the end of the request execution with the final set of parameters
<runscript id="ScriptID" [dpInvoke=now|final] [arg1="value" arg2="value2" ... ]/>
DefProcedure
- Define a procedure
<def_procedure procedureName="name">
any other code
</def_procedure>
CallProcedure
- Call a defined procedure. If _dpIgnoreError is given it will ignore error in the function execution and thread will continue
<call_procedure procedureName="name" [arg1="..." arg2="..." ] [_dpIgnoreError=1/0] assign_attrib />
DispatchProcedure
- Dispatch a request object to defined procedures
- This can be used to match GET/POST requests in application and dispatch it to a request
- Basically if you defined a procedure called doSomething, and the input variable equates to doSomething, doSomething will be called with argumentsVarName (please note you don't have to do $argName here. Just the name of the variable will suffice)
- If there was no procedure defined as with given name, nomatch will be called
- This will return the returned value of the called procedure
- This call will be very handy in reports and custom developer apps to handle Requests
<dispatch_procedure input="varilableName" [argumentsVarName="argumentName"] [nomatch="procedureName"] assign_attrib />
CustomSMS
- Send SMS
<cwa_sms to="destination_number" [message="var"] >message</cwa_sms>
CustomEmail
- Send email
<cwa_email to="destination_address {string or array}" cc="{string or array}" bcc="{string or array}" subject="subject_message" [from="from_replyto_address"] [message="String"] >message</cwa_email>
CustomNotify
- Notify a user through Deputy
<cwa_notify [user="id or login" | emp="id" ] [link="link"] [message="varname or string"]>message</cwa_notify>
CustomSOAP
- Do a SOAP call
<cwa_soap wsdl_url="http[s]://yourservice/soap?wsdl" function="function_tobe_called" [params="params array"] assign_attrib />
DeputyRest
- Call Deputy's REST service methods
- As opposed to making a HTTP call, this call will be executed internally without stepping out
- REST call will happen under the current logged in user. Use sudo to execute under another user
<deputy_rest
url="without api version. E.g. resources/Employee/INFO"
[headers="array of key-values"]
[post="array or string of data (no need to json encode)"]
[method = GET/POST/PUT/DELETE]
[sudo = true | username] If true, use an admin user. If username given then use the user
assign_attribs/>
CustomHTTP
- Do HTTP call
- Headers must be an Array variable
- If you specify useproxy=true, the request will be routed through proxy.deputec.com which has a static IP address
<cwa_http url="http[s]://yourservice/script" [useproxy="no"] [oauthservice="XR|etc"]
[headers="headers_array_var"]
[httpauth="username:password"]
[postdata="string_post_data"]
[customreq="PUT|DELETE"]
assign_attrib/>
CustomOAuth1Header
- Generate the OAuth 1 Auth Header
<cwa_oauth1header
url="the url"
method="method GET|POST"
consumer_key =""
consumer_secret=""
access_key=""
access_secret=""
assign_attrib />
CustomDataSave
- Save custom data if Id is given
<cwa_savedata
document="document_name"
data="data_var_name"
[id="id_int" ]
[label="label_for_data" ]
[operational_unit="operational_unit_id" ]
[employee="employee_id" ]
[key_int|index_int="index_int" ]
[key_string|index_str="index_str" ]
[permission="permission" ]
assign_attrib />
CustomDataDel
- Delete custom data
<cwa_deldata id="id_int" />
CustomGetUser
- Get the current user or user specified by emp or id. Contains user array
<cwa_getuser [id="User id" | emp="Emp id"] assign_attribs />
CustomGetSession
- Gets the current session. Contains session array.
<cwa_getsession assign_attribs />
CustomCheckRole
- Check whether username OR given user's employee profile has part of a specific role
- If no username is given, then the currently logged in user is assumed
<cwa_checkrole role="RoleName" [user="username_or_id"] assign_attribs/>
CustomGetSubordinates
- Get current/given employee's subordinates (Employees)
<cwa_getsubordinates [employee="given employee id OR current employee"] [onlyactive=1] [allcompanies=0] assign_attribs/>
CustomGetCompanies
- Get current employee's companies/business they can manage
<cwa_getcompanies [employee="given employee id OR current employee"] assign_attribs/>
CustomGetAgreements
- Get current/given employee's agreements that might be applicable for a given department/company (if none given then default)
<cwa_getagreements [employee="given employee id OR current employee"] [department=id] [company=id] assign_attribs/>
CustomGetShiftCost
- Given a shift (can be timesheet or roster) calculate the cost of the roster. You can choose whether you want the total value or the distributed cost
<cwa_getshiftcost shift="shiftvariable" [return="total (default)|breakdown"] assign_attribs/>
CustomChargeUsage
- Charge usage
- usage_identifier is for a specific billing Id that has been issued to developer
-If employee is given, an employee will only be charged once per day
<cwa_chargeusage usage="value" desc="Description" [usage_identifier="int"] [employee="Employee ID"] [company="Company ID"] assign_attribs/>
CustomAWSCall
- Call Amazon API solutions (This uses the Amazon SDK for calling specific functions)
<cwa_aws_call library="SDB|S3|SQS|Or any other ones"
method="method_name"
access_key="please specify"
secret_key="please specify"
[account_id="please specify"]
[region="specify region name"]
[input1="input details"]
[input2....]
assign_attribs/>
DownloadFile
- Create a downloadable file by given content
- Returns string of the download URL
- PDF conversions will be done on the fly for html/text files
<cwa_downloadfile title="file title" type="3 letter file extension" content="file content" assign_attribs />
CoreSubmitTask
- Submit task
- If blnUndo is false(default), then task will be submitted after validation
- validation; if checkbox task, check whether the task has been completed, if completed throw error
- else; undo the task after validation
- validation; if checkbox task, check whether the task has been completed, if not completed throw error
- if recurring task, check whether the tasks answer is 0, if it is 0, throw error because we cannot delete the parent task
- else, delete the task and make sure the other recurring tasks answer is -1
<core_addcompletedtask taskId=id [blnUndo=bool] assign_attribs />
CoreAddTimesheet
- Add Timesheet
- If no timesheet id is given, then add a new timesheet
- else update the timesheet
<core_addtimesheet employee=id startTime=timestamp endTime=timestamp opunit=id [mealBreak=int_minutes][timesheetId=Id] assign_attribs />
CoreAddRoster
- Adds a new roster with given employee, start timestamp, endtimestamp, operationalunitid, mealbreak duration
- If provided roster id, then only update that roster after validation
- Return added roster id
- Throw DeXML error if validation fails
<core_addroster employee=id startTime=timestamp endTime=timestamp opunit=id mealBreak=int_minutes [published=bool] assign_attribs/>
CoreGetFile
- Get a file. Usually by returning its download URL from Deputy
- You can also request the file content
Formats:
- thumb: thumbnail url, if it is an image
- tiny30/tiny50: tiny thumbnail url, for 30 or 50 pixels
- orig: the actual objects download link
- content: the file content (can be binary format)
info: File information as array (eg. who uploaded it, when etc...)
<core_getfile id="file id" [format="thumb|orig (default) |content|info"] [assign_attribs] />
CoreGetConfig
- Get config value
<core_config key="config key" [company="Company ID for which you want to get the config key"] [assign_attribs] />
JSONEncode
- Encode given variable as json string
<json_encode input="var" [assign_attribs] />
JSONDecode
- Decode given variable as json string
<json_decode input="varname" [assign_attribs] />
XMLToArray
- Decode a given xml string as an array
<xml_to_array input="varname" [assign_attribs] />
CustomAttachData
- Attach data to given system+id
<cwa_attach_data system="system name" id="id_int" data="data" namespace="give it a name so you can fetch it later" assign_attribs />
CustomGetAttachedData
- Get attached data to given system+id
<cwa_get_attached_data system="system name" id="id_int" namespace="give it a name so you can fetch it later" assign_attribs />
CustomViewLink
- Return exec link for a object
<cwa_view_link system="system name" id="id_int" assign_attribs />
Encrypt
- Simple one-way encryption of data (one-way). Algorithms: md5, sha1
<encrypt algo="varname" input="varname" [rawoutput="0"] [assign_attribs] />
OpenSSL
- Open SSL operations
<openssl function="verify|private_encrypt|public_encrypt|private_decrypt|public_decrypt|sign" [key="The private or public key as string (as PEM)"]
[data="the data"] [signature="signature variable"] [algo="DSS1|SHA1 (default)|MD5|MD4|MD2"] assign_attribs/>
- Performs openssl function on given data and return the results. Certain attributes over here will be required as needed
- Algo is optional and defaults to SHA1
Math
- Provide basic mathematical functionality for two arguments
- op can be & for conatenation
- op can also be functions like abs, sin, cos, rand, floor, round, ceil, number_format etc
Extend
- Extend an array to have save properties as another given array
<extend input="varname" default="another_var_name" assign_attribs />
Map
- Map a procedure to every element of given input array
- The called procedure will have two variables as index and this for the passed vals
- Returns an array with exact same map
<map input="varname" procedureName="procedurename" assign_attribs />
Filter
- Filter an array with given procedure
- The called procedure will have two variables as index and this for the passed vals
- Returns an array with exact same map
<map input="varname" procedureName="procedureName" [groupby="0"] assign_attribs />
GetType
-Typeof
<gettype var="varname" assign_attribs />
String
- String functionalities
<string input="" function="various PHP string functions are available" [arg1=""][arg2=""][arg3=""] assign_attribs />
Array
- Array functionalities
<array input="array var" function="various php array functions" [arg1=""][arg2=""][arg3=""] assign_attribs />
- Special manipulation functions -> unshift, push, last, first, del
Updated over 1 year ago