Skip to main content

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:

nametypedescription
itemIdStringItem id
itemItemJSONObjectItem data
transitionStringWorkflow action name
currentStateStringCurrent state
userUserUser info
screenStringScreen type: view,create,edit
workspaceStringWorkspace id
workspaceKeyStringWorkspace key
itemTypeIdStringItem type id
rolesRole[]System roles
workspaceRolesWorkspaceRole[]Workspace roles

According to the provided parameters, cooperate with the function capabilities provided by the system, and finally return the corresponding field behavior(requiredreadonlyhidden)

Api reference

getScreen

Get screen data

API PARAMETERS:

nametyperequireddescription
screenIdStringtrueScreen 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:

nametyperequireddescription
usersString[]trueUsernames

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:

nametyperequireddescription
itemIdStringtrueItem 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:

nametyperequireddescription
itemIdStringtrueItem 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:

nametyperequireddescription
userIdStringtrueUser 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
}