1
1
# Caché ObjectScript Quick Reference
2
2
A list of some common ObjectScript expressions
3
3
4
- ## Object/SQL Basics
4
+ ## Object/SQL Basics
5
5
6
6
| Action | Code |
7
7
| ----------------------------------------------| -----------------------------------------------------------------------------------|
@@ -38,7 +38,7 @@ A list of some common ObjectScript expressions
38
38
| Test a class query | ` Do ##class(%ResultSet).RunQuery(class, query) ` |
39
39
| Declare a variable's type for Studio Assist | ` #dim object as package.class ` |
40
40
41
- ## ObjectScript Commands
41
+ ## ObjectScript Commands
42
42
43
43
| Command | Description |
44
44
| -------------------------------| -------------------------------------------------------------------------------------|
@@ -56,70 +56,70 @@ A list of some common ObjectScript expressions
56
56
57
57
## ObjectScript Date/Time Functions and Special Variables
58
58
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 ` |
67
67
68
68
## ObjectScript Branching Functions
69
69
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) ` |
74
74
75
75
## ObjectScript String Functions
76
76
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) ` |
80
80
| Display right-justified string within width characters | ` Write $justify(string, width) ` |
81
81
| 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) ` |
83
83
| Display piece from delimited string | ` Write $piece(string, delimiter, pieceNumber) ` |
84
84
| Set piece into delimited string | ` Set $piece(string, delimiter, pieceNumber) = piece ` |
85
85
| Display string after replacing substring | ` Write $replace(string, subString, replaceString) ` |
86
86
| Display reversed string | ` Write $reverse(string) ` |
87
87
| 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) ` |
90
90
| 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) ` |
92
92
93
93
## ObjectScript Existence Functions
94
94
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) ` |
99
99
| Return next valid subscript in array | ` Write $order(array(subscript)) ` |
100
100
101
101
## Additional ObjectScript Functions
102
102
103
- | Action | Code |
104
- | --------------------------------------------------| -------------------------------------------------------------|
103
+ | Action | Code |
104
+ | --------------------------------------------------| -------------------------------------------------------------|
105
105
| Increment ^global by increment | ` $increment(^global, increment) ` <br > ` $sequence(^global, increment) ` |
106
106
| 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 ` |
108
108
109
109
## ObjectScript Special Variables
110
110
111
- | Action | Code |
112
- | -----------------------------------| ---------------------------------------|
111
+ | Action | Code |
112
+ | -----------------------------------| ---------------------------------------|
113
113
| Display process ID | ` Write $job ` |
114
114
| Display current namespace | ` Write $namespace ` |
115
- | Change current namespace | ` Set $namespace = newnamespace ` |
115
+ | Change current namespace | ` Set $namespace = newnamespace ` |
116
116
| Display username | ` Write $username ` |
117
117
| Display roles | ` Write $roles ` |
118
118
119
119
## Utilities
120
120
121
- | Action | Code |
122
- | -----------------------------------| ---------------------------------------|
121
+ | Action | Code |
122
+ | -----------------------------------| ---------------------------------------|
123
123
| Change current namespace | ` Do ^%CD ` <br > ` zn "newnamespace" ` |
124
124
| Display a ^global | ` Do ^%G ` <br > ` zwrite ^global ` |
125
125
0 commit comments