Field Behavior
Introduction
What is field behavior
Field behavior refers to properties(required, read-only, hidden) in form fields
Field behavior script
Field behavior scripts allow for more powerful configuration of field behavior. Field behavior scripts can be added in the field behavior configuration:
Field behavior take effect
After configuring the field behavior, it can take effect in the following forms:
Script parameters
The following parameters can be used directly in the script:
name | type | description |
---|---|---|
itemId | String | Item id |
item | ItemJSONObject | Item data |
transition | String | Workflow action name |
currentState | String | Current state |
user | User | User info |
screen | String | Screen type: view,create,edit |
workspace | String | Workspace id |
workspaceKey | String | Workspace key |
itemTypeId | String | Item type id |
roles | Role[] | System roles |
workspaceRoles | WorkspaceRole[] | Workspace roles |
According to the provided parameters, cooperate with the function capabilities provided by the system, and finally return the corresponding field behavior(required
、readonly
、hidden
)
Api reference
getScreen
Get screen data
API PARAMETERS:
name | type | required | description |
---|---|---|---|
screenId | String | true | Screen id |
RETURN:
ScreenObject - Screen data
interface ScreenObject {
objectId: ObjectId;
name: string;
customFieldKeys: string[];
}
EXAMPLE:
const screenData = await apis.getScreen(screenId);
return {
required: screenData.name === 'screen name',
readonly: false,
hidden: false
}
getUsers
Get users by usernames
API PARAMETERS:
name | type | required | description |
---|---|---|---|
users | String[] | true | Usernames |
RETURN:
SimpleUser[] - Simple user data
interface SimpleUser {
id: string;
username: string;
}
EXAMPLE:
const users = await apis.getUsers(['milo', 'onion', 'osc-admin']);
const isMatch = !!users.find(u => u.username === user.username );
return {
required: isMatch,
readonly: false,
hidden: false
}
getItem
Get item data
API PARAMETERS:
name | type | required | description |
---|---|---|---|
itemId | String | true | Item id |
RETURN:
ItemObjectProps - Item data
EXAMPLE:
const itemData = await apis.getItem(itemId);
return {
required: itemData?.statusName === 'CLOSED',
readonly: false,
hidden: false
}
getWorkflowIdByItemId
Get workflow by item id
API PARAMETERS:
name | type | required | description |
---|---|---|---|
itemId | String | true | Item id |
RETURN:
Workflow - Workflow data
EXAMPLE:
const workflow = await apis.getWorkflowIdByItemId(itemId));
return {
required: workflow?.name === 'SYSTEM DEFAULT WORKFLOW NAME',
readonly: false,
hidden: false
}
getRolesByUserId
Get user role by user id
API PARAMETERS:
name | type | required | description |
---|---|---|---|
userId | String | true | User id |
RETURN:
Role[] - The user system roles
EXAMPLE:
const roles = await apis.getRolesByUserId(user.objectId);
const notMatch = !roles.find(role => role.name === 'QA' );
return {
required: false,
readonly: notMatch,
hidden: false
}