Skip to content

Commit 9a61721

Browse files
committed
Merge pull request #2 from joelsolon/joelsolon-patch-1
Update and rename CHEAT.md to COSQuickRef.md
2 parents 4d350ab + c8d8973 commit 9a61721

File tree

1 file changed

+62
-6
lines changed

1 file changed

+62
-6
lines changed

CHEAT.md renamed to COSQuickRef.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Cheat sheet
2-
Some most encountered COS expressions
1+
# Caché ObjectScript Quick Reference
2+
A list of some common ObjectScript expressions
33

44
## Object/SQL Basics
55

@@ -12,6 +12,7 @@ Some most encountered COS expressions
1212
| Save an object | `Set status = object.%Save()` |
1313
| Retrieve the ID of a saved object | `Set id = object.%Id()` |
1414
| Retrieve the OID of a saved object | `Set oid = object.%Oid()` |
15+
| Determine if an object was modified | `Set variable = object.%IsModified()` |
1516
| Validate an object without saving | `Set status = object.%ValidateObject()` |
1617
| Validate a property without saving | `Set status = ##class(package.class).PropertyIsValid(object.Property)` |
1718
| Print status after error | `Do $system.Status.DisplayError(status)`<br>`Zwrite status` (v2012.2+) |
@@ -23,6 +24,7 @@ Some most encountered COS expressions
2324
| Clone an object | `Set clonedObject = object.%ConstructClone()` |
2425
| Write a property | `Write object.property` |
2526
| Set a property | `Set object.property = value` |
27+
| Write a class parameter | `Write ##class(package.class).#PARAMETER` |
2628
| Set a serial (embedded) property | `Set object.property.embeddedProperty = value` |
2729
| Link two objects | `Set object1.referenceProperty = object2` |
2830
| Populate a class | `Do ##class(package.class).Populate(count, verbose)` |
@@ -33,22 +35,25 @@ Some most encountered COS expressions
3335
| Find classname of an object | `Write $classname(oref)` |
3436
| Start the SQL shell | `Do $system.SQL.Shell()` |
3537
| Test a class query | `Do ##class(%ResultSet).RunQuery(class, query)` |
38+
| Declare a variable's type for Studio Assist | `#dim object as package.class` |
3639

3740
## ObjectScript Commands
3841

3942
| Command | Description |
4043
|-------------------------------|-------------------------------------------------------------------------------------|
4144
| `Write` | Display text strings, value of variable or expression. |
45+
| `Zwrite` | Display array, list string, bit string.
4246
| `Set` | Set value of variable. |
4347
| `Do` | Execute method, procedure, or routine. |
4448
| `Quit` or `Return` (v2013.1) | Terminate method, procedure, or routine. Optionally return value to calling method. |
49+
| `Continue` | Stop current loop iteration, and continue looping. |
4550
| `Halt` | Stop Caché process and close Terminal. |
4651
| `Kill` | Destroy variable(s). |
4752
| `If {} ElseIf {} Else {}` | Evaluate conditions and branch. |
4853
| `For {}`, `While {}`, `Do {} While` | Execute block of code repeatedly. |
4954
| `Try {} Catch {}`, `Throw` | Handle errors. |
5055

51-
## ObjectScript Functions
56+
## ObjectScript Date/Time Functions and Special Variables
5257

5358
| Action | Code |
5459
|--------------------------------------------------|-------------------------------------------------------------|
@@ -58,13 +63,64 @@ Some most encountered COS expressions
5863
| Time conversion (internal → external) | `Set variable = $zt(internalTime, format)` |
5964
| Display current internal date/time string | `Write $horolog` |
6065
| Display UTC date/time string | `Write $ztimestamp` |
61-
| Display length of a string | `Write $length(string)` |
66+
67+
## ObjectScript Branching Functions
68+
69+
| Action | Code |
70+
|--------------------------------------------------|-------------------------------------------------------------|
71+
| Display result for value of expression | `Write $case(expression, value1:result1, value2:result2, …, :resultN)` |
72+
| Display result for first true condition | `Write $select(condition1:result1, condition2:result2, …, 1:resultN)` |
73+
74+
## ObjectScript String Functions
75+
76+
| Action | Code |
77+
|--------------------------------------------------|-------------------------------------------------------------|
78+
| Display substring extracted from string | `Write $extract(string, start, end)` |
79+
| Display right-justified string within width characters | `Write $justify(string, width)` |
80+
| Display length of string | `Write $length(string)` |
81+
| Display number of delimited pieces in string | `Write $length(string, delimiter)` |
82+
| Display piece from delimited string | `Write $piece(string, delimiter, pieceNumber)` |
83+
| Set piece into delimited string | `Set $piece(string, delimiter, pieceNumber) = piece` |
84+
| Display string after replacing substring | `Write $replace(string, subString, replaceString)`|
85+
| Display reversed string | `Write $reverse(string)` |
86+
| Display string after replacing characters | `Write $translate(string, searchChars, replaceChars)` |
6287
| Build a list | `Set listString = $listbuild(list items, separated by comma)` |
6388
| Retrieve an item from a list | `Set variable = $list(listString, position)` |
89+
| Put item into list string | `Set $list(listString, position) = substring` |
6490
| Display the length of a list | `Write $listlength(listString)` |
91+
92+
## ObjectScript Existence Functions
93+
94+
| Action | Code |
95+
|--------------------------------------------------|-------------------------------------------------------------|
96+
| Check if variable exists | `Write $data(variable)` |
97+
| Return value of variable, or default If undefined | `Write $get(variable, default)` |
98+
| Return next valid subscript in array | `Write $order(array(subscript))` |
99+
100+
## Additional ObjectScript Functions
101+
102+
| Action | Code |
103+
|--------------------------------------------------|-------------------------------------------------------------|
104+
| Increment ^global by increment | `$increment(^global, increment)` <br> `$sequence(^global, increment)` |
105+
| Match a regular expression | `Set matches = $match(string, regularexpression)` |
65106
| Display random integer from start to start+count | `Write $random(count) + start` |
66-
| Check if variable exists | `Write $data(variable)` |
67-
| Return value of variable, or "" If undefined | `Write $get(variable)` |
107+
108+
## ObjectScript Special Variables
109+
110+
| Action | Code |
111+
|--------------------------------------------------|-------------------------------------------------------------|
112+
| Display process ID | `Write $job` |
113+
| Display current namespace | `Write $namespace` |
114+
| Change current namespace | `Set $namespace = newnamespace` |
115+
| Display username | `Write $username` |
116+
| Display roles | `Write $roles` |
117+
118+
## Utilities
119+
120+
| Action | Code |
121+
|--------------------------------------------------|-------------------------------------------------------------|
122+
| Change current namespace | `Do ^%CD` <br> `zn "newnamespace"` |
123+
| Display a ^global | `Do ^%G` <br> `zwrite ^global` |
68124

69125
## Collections
70126

0 commit comments

Comments
 (0)