context
Overview¶
The "Server Script" is used to reference user request information such as user IDs and site IDs. It is also used for data sharing between scripts, logging, and message output.
Properties¶
| No | Name | Get | Set | Type | Description |
|---|---|---|---|---|---|
| 1 | UserData | Yes | Yes | ExpandoObject | Allow data sharing between scripts |
| 2 | QueryStrings | Yes | No | Object | Get the value of URL query parameters |
| 3 | Forms | Yes | No | Forms | Get form information |
| 4 | FormStringRaw | Yes | No | string | Information entered in the form (column) |
| 5 | FormString | Yes | No | string | Information entered in the form (column) |
| 6 | Ajax | Yes | No | bool | Flag indicating whether the request was made via Ajax |
| 7 | Mobile | Yes | No | bool | Flag indicating whether the request was made via Mobile |
| 8 | ApplicationPath | Yes | No | string | Application path |
| 9 | AbsoluteUri | Yes | No | string | Absolute URI |
| 10 | AbsolutePath | Yes | No | string | Absolute path |
| 11 | Url | Yes | No | string | URL |
| 12 | UrlReferrer | Yes | No | string | Previously requested URL |
| 13 | Controller | Yes | No | string | Controller name |
| 14 | Query | Yes | No | string | URL query parameters |
| 15 | Action | Yes | No | string | Action name |
| 16 | TenantId | Yes | No | int | Tenant ID |
| 17 | SiteId | Yes | No | long | Site ID |
| 18 | Id | Yes | No | long | Record ID |
| 19 | Groups | Yes | No | IEnumerable | Collection of group IDs of groups to which the user belongs |
| 20 | TenantTitle | Yes | No | string | Tenant title |
| 21 | SiteTitle | Yes | No | string | Site title |
| 22 | RecordTitle | Yes | No | string | Record title |
| 23 | DeptId | Yes | No | int | Department ID |
| 24 | UserId | Yes | No | int | User ID |
| 25 | LoginId | Yes | No | string | Log ID |
| 26 | Language | Yes | No | string | Setting language |
| 27 | TimeZoneInfo | Yes | No | string | Time zone |
| 28 | HasPrivilege | Yes | No | bool | Flag indicating whether the operating user is a privileged user |
| 29 | ApiVersion | Yes | No | decimal | API version |
| 30 | ApiRequestBody | Yes | No | string | API request content |
| 31 | RequestDataString | Yes | No | string | Request data |
| 32 | ContentType | Yes | No | string | Response header type |
| 33 | ControlId | Yes | No | string | Request source control ID |
| 34 | Condition | Yes | No | string | Name of server script condition |
Methods¶
| No | Name | Description |
|---|---|---|
| 1 | AddMessage | Output a message at the bottom of the browser screen. |
| 2 | Error | Cancel the user's create, update, or delete operation and outputs an error message. |
| 3 | Log | Output a log to the browser console. |
| 4 | Redirect | Cause the browser to transition to a new page. |
| 5 | AddResponse | Return an arbitrary client response. |
| 6 | ResponseSet | Store information in a form. |
Usage Example 1¶
In the example below, if the user ID of the logged-in user is not 1, the filter will display only records whose creator is own. The condition is checked "When Processing Views."
JavaScript¶
Usage Example 2¶
The following example outputs to the log the group IDs of all groups to which the logged-in user belongs.
JavaScript¶
Code Samples¶
Notes
Modify 【 ... 】 in the code as necessary.
1. Run a server script when an arbitrary process is executed
Use context.ControlId to determine which process was executed, and run an arbitrary server script process.
Execution Result¶
2. Control screen items according to the attributes of the logged-in user
Control the screen items (with columns.ReadOnly,Hide) according to the attributes of the logged-in user (determined with context.HasPrivilege and context.Groups) and the status. The sample code implements the following specifications.
Determining the control pattern
| User type | Status | Control pattern |
|---|---|---|
| Privileged user | - | Pattern A |
| User who belongs to an administrator group (ID 1, 2) | - | Pattern B |
| Other users | Completed (900) or On hold (910) | Pattern C |
| Other users | Other than the above | Pattern D |
Controlling screen items
| Screen item | Column ID | Pattern A | Pattern B | Pattern C | Pattern D |
|---|---|---|---|---|---|
| Title | Title | Editable | Editable | Read only | Editable |
| Body | Body | Editable | Editable | Read only | Editable |
| Status | Status | Editable | Editable | Read only | Editable |
| Classification A | ClassA | Editable | Editable | Read only | Editable |
| Classification B | ClassB | Editable | Read only | Hidden | Hidden |
| Date A | DateA | Editable | Read only | Read only | Editable |
| Description A | DescriptionA | Editable | Editable | Hidden | Hidden |
JavaScript¶
Condition: Before opening the page
Execution Result¶
Supported Versions¶
| Supported versions | Body |
|---|---|
| 1.4.17.0 and later | Added the context.ReferenceType property to server scripts |
| 1.4.17.0 and later | Added the context.HttpMethod property to server scripts |
Related Information¶
- Manage Table: Server Script
- Developer's Guide: Server Script: context.UserData
- Developer's Guide: Server Script: context.QueryStrings
- Developer's Guide: Server Script: context.Forms
- Developer's Guide: Server Script: context.AddMessage
- Developer's Guide: Server Script: context.Error
- Developer's Guide: Server Script: context.Log
- Developer's Guide: Server Script: context.Redirect
- Developer's Guide: Server Script: context.AddResponse
- Developer's Guide: Server Script: context.ResponseSet