11# Caché ObjectScript Quick Reference
22A list of some common ObjectScript expressions
33
4- ## Object/SQL Basics
4+ ## Object/SQL Basics
55
66| Action | Code |
77| ----------------------------------------------| -----------------------------------------------------------------------------------|
@@ -38,7 +38,7 @@ A list of some common ObjectScript expressions
3838| Test a class query | ` Do ##class(%ResultSet).RunQuery(class, query) ` |
3939| Declare a variable's type for Studio Assist | ` #dim object as package.class ` |
4040
41- ## ObjectScript Commands
41+ ## ObjectScript Commands
4242
4343| Command | Description |
4444| -------------------------------| -------------------------------------------------------------------------------------|
@@ -56,70 +56,70 @@ A list of some common ObjectScript expressions
5656
5757## ObjectScript Date/Time Functions and Special Variables
5858
59- | Action | Code |
60- | --------------------------------------------------| -------------------------------------------------------------|
61- | Date conversion (external → internal) | ` Set variable = $zdh("mm/dd/yyyy") ` |
62- | Date conversion (internal → external) | ` Set variable = $zd(internalDate, format) ` |
63- | Time conversion (external → internal) | ` Set variable = $zth("hh:mm:ss") ` |
64- | Time conversion (internal → external) | ` Set variable = $zt(internalTime, format) ` |
65- | Display current internal date/time string | ` Write $horolog ` |
66- | Display UTC date/time string | ` Write $ztimestamp ` |
59+ | Action | Code |
60+ | --------------------------------------------------| -------------------------------------------------------------|
61+ | Date conversion (external → internal) | ` Set variable = $zdh("mm/dd/yyyy") ` |
62+ | Date conversion (internal → external) | ` Set variable = $zd(internalDate, format) ` |
63+ | Time conversion (external → internal) | ` Set variable = $zth("hh:mm:ss") ` |
64+ | Time conversion (internal → external) | ` Set variable = $zt(internalTime, format) ` |
65+ | Display current internal date/time string | ` Write $horolog ` |
66+ | Display UTC date/time string | ` Write $ztimestamp ` |
6767
6868## ObjectScript Branching Functions
6969
70- | Action | Code |
71- | --------------------------------------------------| ------------------------------------------------------------------------|
72- | Display result for value of expression | ` Write $case(expression, value1:result1, value2:result2, …, :resultN) ` |
73- | Display result for first true condition | ` Write $select(condition1:result1, condition2:result2, …, 1:resultN) ` |
70+ | Action | Code |
71+ | --------------------------------------------------| ------------------------------------------------------------------------|
72+ | Display result for value of expression | ` Write $case(expression, value1:result1, value2:result2, …, :resultN) ` |
73+ | Display result for first true condition | ` Write $select(condition1:result1, condition2:result2, …, 1:resultN) ` |
7474
7575## ObjectScript String Functions
7676
77- | Action | Code |
78- | ----------------------------------------------------------| ---------------------------------------------------------------|
79- | Display substring extracted from string | ` Write $extract(string, start, end) ` |
77+ | Action | Code |
78+ | ----------------------------------------------------------| ---------------------------------------------------------------|
79+ | Display substring extracted from string | ` Write $extract(string, start, end) ` |
8080| Display right-justified string within width characters | ` Write $justify(string, width) ` |
8181| Display length of string | ` Write $length(string) ` |
82- | Display number of delimited pieces in string | ` Write $length(string, delimiter) ` |
82+ | Display number of delimited pieces in string | ` Write $length(string, delimiter) ` |
8383| Display piece from delimited string | ` Write $piece(string, delimiter, pieceNumber) ` |
8484| Set piece into delimited string | ` Set $piece(string, delimiter, pieceNumber) = piece ` |
8585| Display string after replacing substring | ` Write $replace(string, subString, replaceString) ` |
8686| Display reversed string | ` Write $reverse(string) ` |
8787| Display string after replacing characters | ` Write $translate(string, searchChars, replaceChars) ` |
88- | Build a list | ` Set listString = $listbuild(list items, separated by comma) ` |
89- | Retrieve an item from a list | ` Set variable = $list(listString, position) ` |
88+ | Build a list | ` Set listString = $listbuild(list items, separated by comma) ` |
89+ | Retrieve an item from a list | ` Set variable = $list(listString, position) ` |
9090| Put item into list string | ` Set $list(listString, position) = substring ` |
91- | Display the length of a list | ` Write $listlength(listString) ` |
91+ | Display the length of a list | ` Write $listlength(listString) ` |
9292
9393## ObjectScript Existence Functions
9494
95- | Action | Code |
96- | --------------------------------------------------| -------------------------------------------------------------|
97- | Check if variable exists | ` Write $data(variable) ` |
98- | Return value of variable, or default If undefined | ` Write $get(variable, default) ` |
95+ | Action | Code |
96+ | --------------------------------------------------| -------------------------------------------------------------|
97+ | Check if variable exists | ` Write $data(variable) ` |
98+ | Return value of variable, or default If undefined | ` Write $get(variable, default) ` |
9999| Return next valid subscript in array | ` Write $order(array(subscript)) ` |
100100
101101## Additional ObjectScript Functions
102102
103- | Action | Code |
104- | --------------------------------------------------| -------------------------------------------------------------|
103+ | Action | Code |
104+ | --------------------------------------------------| -------------------------------------------------------------|
105105| Increment ^global by increment | ` $increment(^global, increment) ` <br > ` $sequence(^global, increment) ` |
106106| Match a regular expression | ` Set matches = $match(string, regularexpression) ` |
107- | Display random integer from start to start+count | ` Write $random(count) + start ` |
107+ | Display random integer from start to start+count | ` Write $random(count) + start ` |
108108
109109## ObjectScript Special Variables
110110
111- | Action | Code |
112- | -----------------------------------| ---------------------------------------|
111+ | Action | Code |
112+ | -----------------------------------| ---------------------------------------|
113113| Display process ID | ` Write $job ` |
114114| Display current namespace | ` Write $namespace ` |
115- | Change current namespace | ` Set $namespace = newnamespace ` |
115+ | Change current namespace | ` Set $namespace = newnamespace ` |
116116| Display username | ` Write $username ` |
117117| Display roles | ` Write $roles ` |
118118
119119## Utilities
120120
121- | Action | Code |
122- | -----------------------------------| ---------------------------------------|
121+ | Action | Code |
122+ | -----------------------------------| ---------------------------------------|
123123| Change current namespace | ` Do ^%CD ` <br > ` zn "newnamespace" ` |
124124| Display a ^global | ` Do ^%G ` <br > ` zwrite ^global ` |
125125
0 commit comments