Skip to content

informat.system System Global Operations

Overview

Use the informat.system object to perform global operations on the system. Global operations require the System Function Call module to be included in the license.

serverId

Query server node ID

javascript
informat.system.serverId();

Return Value Type: String Returns the server node ID.

The server node ID value is from the informat-next/instance/informat-xxxx/application.yml file, under the spring > application > serverId configuration item.

Example

javascript
informat.system.serverId(); // informat2-biz-prd

host

Return the system's home page address

javascript
informat.system.host();

Return Value Type: String Returns the system's home page address.

Example

javascript
informat.system.host();
// Returns
https://next.informat.cn/

getAccount

Query account information

javascript
informat.system.getAccount(id);
ParameterTypeDescription
idStringAccount ID

Return Value Type: Account Returns the account information. If the account does not exist, null is returned.

Example

Assuming that the system has an account with ID lwfwqr67xsvup and the user is named mr.zhang

javascript
informat.system.getAccount("lwfwqr67xsvup");

Return Value

json
{
  "avatar": "pic16.png",
  "companyId": "g09aj7cus3d8s",
  "createTime": 1664200514136,
  "email": "zhangsan@example.com",
  "id": "lwfwqr67xsvup",
  "isValid": true,
  "mobileNo": "13012345678",
  "name": "mr.zhang",
  "oid": "zhangsan",
  "updateTime": 1683598262000,
  "userName": "zhangsan",
  "valid": true
}

getAccountByUserName

Query account information by username

javascript
informat.system.getAccountByUserName(userName);
ParameterTypeDescription
userNameStringUsername

Return Value Type: Account Returns the account information. If the account does not exist, null is returned.

Example

Assuming that the system has a user named mr.zhang with the username zhangsan

javascript
informat.system.getAccountByUserName("zhangsan");

Return Value

json
{
  "avatar": "pic16.png",
  "companyId": "g09aj7cus3d8s",
  "createTime": 1664200514136,
  "email": "zhangsan@example.com",
  "id": "lwfwqr67xsvup",
  "isValid": true,
  "mobileNo": "13012345678",
  "name": "mr.zhang",
  "oid": "zhangsan",
  "updateTime": 1683598262000,
  "userName": "zhangsan",
  "valid": true
}

getAccountByMobileNo

Query account information by mobile number

javascript
informat.system.getAccountByMobileNo(mobileNo);
ParameterTypeDescription
mobileNoStringMobile number

Return Value Type: Account Returns the account information. If the account does not exist, null is returned.

Example

Assuming that the system has a user named mr.zhang with the mobile number 13012345678

javascript
informat.system.getAccountByMobileNo("13012345678");

Return Value

json
{
  "avatar": "pic16.png",
  "companyId": "g09aj7cus3d8s",
  "createTime": 1664200514136,
  "email": "zhangsan@example.com",
  "id": "lwfwqr67xsvup",
  "isValid": true,
  "mobileNo": "13012345678",
  "name": "mr.zhang",
  "oid": "zhangsan",
  "updateTime": 1683598262000,
  "userName": "zhangsan",
  "valid": true
}

getAccountByEmail

Query account information by email address

javascript
informat.system.getAccountByEmail(email);
ParameterTypeDescription
emailStringEmail address

Return Value Type: Account Returns the account information. If the account does not exist, null is returned.

Example

Assuming that the system has a user named mr.zhang with the email address zhangsan@example.com

javascript
informat.system.getAccountByEmail("zhangsan@example.com");

Return Value

json
{
  "avatar": "pic16.png",
  "companyId": "g09aj7cus3d8s",
  "createTime": 1664200514136,
  "email": "zhangsan@example.com",
  "id": "lwfwqr67xsvup",
  "isValid": true,
  "mobileNo": "13012345678",
  "name": "mr.zhang",
  "oid": "zhangsan",
  "updateTime": 1683598262000,
  "userName": "zhangsan",
  "valid": true
}

queryAccountList

Query account list

javascript
informat.system.queryAccountList(query);
ParameterTypeDescription
queryQueryAccount query conditions

Return Value Type: Array [Account](/guide/script/model.md#account) Returns the account list. If no account is found, an empty array is returned.

FieldTypeDescription
idStringAccount ID
nameStringName
userNameStringUsername
mobileNoStringMobile number
emailStringEmail address
oidStringThird-party ID

Return Value Type: Array [Account](/guide/script/model.md#account) Returns the account list. If no account is found, an empty array is returned.

Example

javascript
informat.system.queryAccountList({
  pageIndex: 1,
  pageSize: 10,
  filter: {
    conditionList: [
      {
        fieldId: "userName",
        opt: "contains",
        value: "zhang",
      },
    ],
  },
});

Return Value

json
[
  {
    "avatar": "pic16.png",
    "companyId": "g09aj7cus3d8s",
    "createTime": 1664200514136,
    "email": "zhangsan@example.com",
    "id": "lwfwqr67xsvup",
    "isValid": true,
    "mobileNo": "13012345678",
    "name": "mr.zhang",
    "oid": "zhangsan",
    "updateTime": 1683598262000,
    "userName": "zhangsan",
    "valid": true
  },
  {
    "avatar": "pic23.png",
    "createTime": 1675836165076,
    "id": "x3q3npo3xsait",
    "isValid": true,
    "mobileNo": "18291909205",
    "name": "mr.zhang",
    "updateTime": 1683594979000,
    "userName": "zhangrongli",
    "valid": true
  },
  {
    "avatar": "pic13.png",
    "createTime": 1682307631474,
    "email": "zhangrongfu@itit.io",
    "id": "wlt9cgr70o0yi",
    "isValid": true,
    "mobileNo": "15989268009",
    "name": "mr.zhang",
    "updateTime": 1683335991000,
    "userName": "zhangrongfu",
    "valid": true
  }
]

queryAccountListCount

Query account list total count

javascript
informat.system.queryAccountListCount(filter);
ParameterTypeDescription
filterFilterAccount query conditions

Return Value Type: Integer Returns the total number of accounts that match the query conditions. If no account is found, 0 is returned.

Example

javascript
informat.system.queryAccountListCount({
  conditionList: [
    {
      fieldId: "userName",
      opt: "contains",
      value: "zhang",
    },
  ],
}); // Returns 3

addAccount

Add account

javascript
informat.system.addAccount(account);
ParameterTypeDescription
accountAccountAccount information, ID and creation time are not required

Return Value Type: String Returns the ID of the newly added account.

Example 1 Add Account

js
informat.system.addAccount({
    name: 'test',
    avatar: 'pic15.png',
    userName: 'test',
    mobileNo: '13800000000',
    email: 'test@informat.cn',
    password: 'youpassword'
});
json
"ap1cew2up9ehq"

Example 2 Add Account with Specified ID

js
informat.system.addAccount({
	id: 'zhangsan',
    name: 'test',
    avatar: 'pic15.png',
    userName: 'zhangsan',
    mobileNo: '13800000000',
    email: 'zhangsan@informat.cn',
    password: 'youpassword'
});
json
"zhangsan"

updateAccount

Update account information

javascript
informat.system.updateAccount(account);
ParameterTypeDescription
accountAccountAccount information

Can update the following fields:

FieldTypeDescription
oidStringIdentifier
nameStringName
userNameStringUsername
mobileNoStringMobile number
emailStringEmail address
avatarStringAvatar image
languageStringLanguage
needUpdatePasswordBooleanWhether to force password update

Return Value Type: Integer Returns the number of accounts updated. If no account is found, 0 is returned.

Example 1 Update Account

js
informat.system.updateAccount({
    id: 'ap1cew2up9ehq',
    name: 'test2',
    avatar: 'pic16.png',
    userName: 'test2',
    mobileNo: '13700000000',
    email: 'test2@informat.cn'
});
json
1

updateAccountList

Update account list

javascript
informat.system.updateAccountList(account, filter);
ParameterTypeDescription
accountAccountAccount information
filterFilterAccount query conditions

Can update the following fields:

FieldTypeDescription
oidStringIdentifier
nameStringName
userNameStringUsername
mobileNoStringMobile number
emailStringEmail address
avatarStringAvatar image
languageStringLanguage
needUpdatePasswordBooleanWhether to force password update

Return Value Type: Integer Returns the number of accounts updated. If no account is found, 0 is returned.

Example 1 Update Account List

js
informat.system.updateAccountList(
    {
        name: 'test2',
        avatar: 'pic15.png',
        userName: 'test2',
        mobileNo: '13900000000',
        email: 'test2@informat.cn'
    },
    {
        conditionList: [
            { 'fieldId': 'id', 'opt': 'eq', 'value': 'ap1cew2up9ehq' }
        ]
    }
);
json
1

changePassword

Change account password

javascript
informat.system.changePassword(accountId, pwd);
ParameterTypeDescription
accountIdStringAccount ID
pwdStringPassword

createToken

Create login token for account

javascript
informat.system.createToken(accountId, type);
ParameterTypeDescription
accountIdStringAccount ID
typeStringToken type
PC index
mobile
mobile survey
surveyweb
Exclude system built-in types, also support custom types (e.g.: app, wechat, wemp, etc.)

Return Value Type: String Returns the authorized TOKEN.

Example

javascript
informat.system.createToken("wlt9cgr70o0yi", "index");
json
"581aa91125e74a74a07747ef6862ba41"

getAccountByToken

Look up account information by TOKEN

javascript
informat.system.getAccountByToken(token);
ParameterTypeDescription
tokenStringTOKEN

Return Value

Type: Account Returns account information. If the TOKEN does not exist, an empty object is returned.

Example

js
informat.system.getAccountByToken("581aa91125e74a74a07747ef6862ba41");
json
{
    "avatar": "pic16.png",
    "companyId": "g09aj7cus3d8s",
    "createTime": 1664200514136,
    "email": "zhangsan@example.com",
    "id": "lwfwqr67xsvup",
    "isValid": true,
    "mobileNo": "13012345678",
    "name": "mr. zhang",
    "oid": "zhangsan",
    "updateTime": 1683598262000,
    "userName": "zhangsan",
    "valid": true
}

login

Login account

javascript
informat.system.login(loginForm);
ParameterTypeDescription
loginFormLoginFormUsername or mobile number or email address

Return Value

Type: LoginResult

ParameterTypeDescription
accountIdStringAccount ID
companyIdStringCompany ID
errorCodeIntegerError code
tokenStringLogin token

Return Value

Type: LoginResult Returns the login result. If the login fails, an error message is returned.

Example

js
informat.system.login({
	userName:'zhangsan',
	password:'12345678',
	type:'mobile',
	ip:'183.46.24.11'
})
json
{
"accountId":"zhangsan",
"companyId":"g09aj7cus3d8s",
"errorCode":0,
"token":"2f7536034b3748c9ba7db15759d01f26"
}

validateAccount

Validate username and password

javascript
informat.system.validateAccount(user, pwd);
ParameterTypeDescription
userStringUsername or mobile number
pwdStringPassword

Return Value

If the username and password are valid, it returns true; otherwise, it returns false. The type is Boolean.

javascript
informat.system.validateAccount("zhangsan", "12345678"); // false

setAccountValid

Enable/disable account

javascript
informat.system.setAccountValid(accountId, isValid);
ParameterTypeDescription
accountIdStringAccount ID
isValidBooleanWhether to enable or disable the account

Example

javascript
// Disable the account of mr. zhang
informat.system.setAccountValid("lwfwqr67xsvup", false);
// Enable the account of mr. zhang
informat.system.setAccountValid("lwfwqr67xsvup", true);

invokeLibrary

Call a function from an extension library

For more information about libraries, please refer to Libraries

javascript
informat.system.invokeLibrary(libraryId, className, method, args);
ParameterTypeDescription
libraryIdStringLibrary identifier
classNameStringFully qualified class name in the library, e.g. com.mycompany.MyLibaray
methodStringMethod name to be called, must be static
argsArrayArray of arguments to pass to the method, or null if no arguments

Return Value

Type: Object Returns the return value of the method in the library.

Below is an example

javascript
informat.system.invokeLibrary("mylibrary", "com.mycompany.MyLibaray", "add", [1, 2]);

If the extension-library function has no parameters

javascript
informat.system.invokeLibrary("mylibrary", "com.mycompany.MyLibaray", "test", null);
informat.system.invokeLibrary("mylibrary", "com.mycompany.MyLibaray", "test");

For more detailed instructions, please refer to 考Libraries

runProcess

Launch a new process to run the specified command.

javascript
informat.system.runProcess(args);
ParameterTypeDescription
argsProcessRunArgsExecution arguments

ProcessRunArgs Structure

AttributeTypeDescription
argsArray<String>Command arguments
timeoutIntegerTimeout in milliseconds, 0 means ignore timeout

Return Value

Type: ProcessRunResult

AttributeTypeDescription
exitValueIntegerExit code
outStringStandard output
errStringError output

Below is an example

javascript
const result = informat.system.runProcess({
  cmds: ["java", "-version"],
  timeout: 0,
});
console.log(result.out); // java version "11.0.5" 2019-10-15 LTS

runNodeJS

Launch a new process to run Node.js; pass arguments via command-line parameters (cmdline) and standard input (stdin). The Node.js process uses standard output and standard error as return values.

javascript
informat.system.runNodeJS(args);
ParameterTypeDescription
argsRunNodeJSArgsExecution arguments

RunNodeJSArgs Structure

AttributeTypeDescription
scriptStringScript file to execute, e.g. test/helloworld.js
cmdlineArray<String>Command line arguments, subject to operating system length limitations, e.g. 131071 on Linux
stdinStringStandard input
envObjectEnvironment variables

Return Value

Type: ProcessRunResult

AttributeTypeDescription
exitValueIntegerExit code
outStringStandard output
errStringError output

Example:

The test script file nodejs/md5test.js is as follows:

javascript
/**
 *Use the md5 library to compute the MD5 hash of the input string; pass the input parameter via the command line.
 */
var arguments = process.argv;
//Retrieve input parameters
let input = arguments[2];
var md5 = require("md5");
//Pass the result via standard output
console.log(md5(input));

Here is the Node.js code to call:

javascript
var result = informat.system.runNodeJS({
  script: "nodejs/md5test.js",
  cmdline: ["123456"],
});
console.log("md5 value:", result.out);

queryCompanyList

Query team list

javascript
informat.system.queryCompanyList(query);
ParameterTypeDescription
queryQueryQuery filter

Fields available in the filter

FieldTypeDescription
idStringAccount ID
nameStringName

Return Value Return account list, value type is Array Company

Example

js
informat.system.queryCompanyList({
    pageIndex: 1,
    pageSize: 10,
    filter: {
        conditionList: [
            {
                fieldId: 'name',
                opt: 'contains',
                value: 'test'
            }
        ]
    }
});
json
[
  {
    "createAccountId":"zhangsan",
    "createTime":1665404532125,
    "dbIndex":0,
    "id":"ukswiyvmqlq5n",
    "maxApplicationNum":0,
    "maxUserNum":0,
    "name":"test team",
    "updateTime":1704353335727,
    "version":"free"
  },
  {
    "createAccountId":"zhangsan",
    "createTime":1669306766288,
    "dbIndex":0,
    "id":"kkoixbg8ew3ks",
    "maxApplicationNum":0,
    "maxUserNum":0,
    "name":"test team",
    "updateTime":1713920870106,
    "version":"enterprise"
  }
]

queryCompanyListCount

Get total count of teams

javascript
informat.system.queryCompanyListCount(filter);
ParameterTypeDescription
filterFilterQuery filter

Fields available in the filter

FieldTypeDescription
idStringAccount ID
nameStringName

Return Value Type: Integer Return total number of teams

Example

js
informat.system.queryCompanyListCount({
    conditionList: [
        {
            fieldId: 'name',
            opt: 'contains',
            value: 'test'
        }
    ]
});
json
2

addCompanyMember

Add team member

javascript
informat.system.addCompanyMember(companyId, accountId, departmentList, roleList);
ParameterTypeDescription
companyIdStringQuery filter
accountIdStringQuery filter
departmentListArray(String)Department list
roleListArray(String)Role list

Return Value

Type: Integer

Description: Number of operation records

Example

javascript
informat.system.addCompanyMember("g09aj7cus3d8s", "skydu2", ["dev"], ["member"]);

queryCompanyDeptList

Query department list in the team

javascript
informat.system.queryCompanyDeptList(companyId, query);
ParameterTypeDescription
companyIdStringTeam ID
queryQueryQuery condition

List of fields available in the filter

ParameterTypeDescription
idStringDepartment ID
parentIdStringParent department ID
nameStringDepartment name
createTimeDateCreate time

Return Value Type: Array Dept Return department list

Example 1 Query department list with name containing "dev"

js
informat.system.queryCompanyDeptList(
	'g09aj7cus3d8s',{
    pageSize:-1,
    filter:{
        conditionList:[
            {"fieldId":"name","opt":"contains","value":"dev"}
        ]
    }
});
json
[
  {
    "id": "yanfabu",
    "name": "R&D Department",
    "parentId": "root",
    "remark": "Department responsible for researching and developing new products, technologies, or services",
    "rowNumber": 2,
    "shortName": "R&D Dept."
  }
]

getCompanyAllRoles

Query all roles in the team

javascript
informat.system.getCompanyAllRoles(companyId);
ParameterTypeDescription
companyIdStringTeam ID

Return Value

Type: Array CompanyRole Return all roles

Example

js
informat.system.getCompanyAllRoles('g09aj7cus3d8s')
json
[
  {
    "admin": true,
    "createTime": 1664196760903,
    "id": "admin",
    "isAdmin": true,
    "name": "Administrator",
    "permissionIds": [

    ]
  },
  {
    "admin": false,
    "createTime": 1664196760907,
    "id": "member",
    "isAdmin": false,
    "name": "Member",
    "permissionIds": [
      "InviteMember"
    ]
  }
]

addOptLog

Add system log

javascript
informat.system.addOptLog(optLog);

Parameters

ParameterTypeDescription
optLogOptLogNew operation log

OptLog structure: ``

FieldTypeDescription
idStringOperation record ID
typeStringOperation type
accountIdStringOperator ID
companyIdStringTeam ID
associatedIdStringAssociated ID
remarkStringRemarks, appended after operation details

Optional values for operation type:

Operation TypeDescription
CreateAccountCreate Account
UpdateAccountUpdate Account
RegisterRegister
PasswordLoginUsername & Password Login
WechatLoginWeChat QR-Code Login
MobileNoLoginMobile SMS-Code Login
DingTalkLoginDingTalk Seamless Login
WeWorkLoginWeCom (WeChat Work) Seamless Login
ssoLoginSSO Login
LogoutLogout
UpdateUserNameChange Login Name
UpdateNickNameChange Nickname
UpdateMobileNoChange Mobile Number
UpdateEmailChange Email
SwitchCompanySwitch Team
InviteMemberInvite Member
DeleteMemberRemove Member
CreateDepartmentCreate Department
UpdateDepartmentEdit Department
DeleteDepartmentDelete Department
CreateRoleCreate Role
UpdateRoleEdit Role
DeleteRoleDelete Role
CreateCompanyCreate Team
CompanySetProSet Trial Mode
CompanySetModuleConfigure Modules
CreateAppCreate App
UpdateAppEdit App
DeleteAppDelete App
ArchiveAppArchive App
CreateAppMemberAdd App Member
UpdateAppMemberEdit App Member
DeleteAppMemberRemove App Member
UpdateAppMemberAccessPasswordChange App-Member Access Password
CreateAppModuleAdd App Module
DeleteAppModuleRemove App Module
DeleteRecycleBinEmpty Recycle Bin

Return Value

Type: Integer

Description: Number of operation records

Example

js
let optlog = {
  accountId: informat.app.userId(),
  type: "CreateAccount",
  companyId: informat.company.getCompany().id,
  remark: "(log)",
};
informat.system.addOptLog(optlog);

queryOptLogList

Query operation record list

js
informat.system.queryOptLogList(query);

Parameters

ParameterTypeDescription
queryQueryQuery conditions

queryOptLogList Filter Fields

FieldTypeDescription
typeStringOperation type
accountIdStringUser who performed the operation
remarkStringRemark / Note
createTimeStringCreation timestamp
updateTimeStringLast update timestamp

Optional values for operation type:

Operation TypeDescription
CreateAccountCreate Account
UpdateAccountUpdate Account
RegisterRegister
PasswordLoginUsername & Password Login
WechatLoginWeChat QR-Code Login
MobileNoLoginMobile SMS-Code Login
DingTalkLoginDingTalk Seamless Login
WeWorkLoginWeCom (WeChat Work) Seamless Login
ssoLoginSSO Login
LogoutLogout
UpdateUserNameChange Login Name
UpdateNickNameChange Nickname
UpdateMobileNoChange Mobile Number
UpdateEmailChange Email
SwitchCompanySwitch Team
InviteMemberInvite Member
DeleteMemberRemove Member
CreateDepartmentCreate Department
UpdateDepartmentEdit Department
DeleteDepartmentDelete Department
CreateRoleCreate Role
UpdateRoleEdit Role
DeleteRoleDelete Role
CreateCompanyCreate Team
CompanySetProSet Trial Mode
CompanySetModuleConfigure Modules
CreateAppCreate App
UpdateAppEdit App
DeleteAppDelete App
ArchiveAppArchive App
CreateAppMemberAdd App Member
UpdateAppMemberEdit App Member
DeleteAppMemberRemove App Member
UpdateAppMemberAccessPasswordChange App-Member Access Password
CreateAppModuleAdd App Module
DeleteAppModuleRemove App Module
DeleteRecycleBinEmpty Recycle Bin

queryOptLogList Return Value

Type: Array OptLog, operation record list

queryOptLogList Example

js
let query = {
    pageSize:-1,
    filter: {
        conditionList:[
            {fieldId:'type', opt: 'eq', value: 'CreateAccount'}
        ]
    }
}
informat.system.queryOptLogList(query)
json
[
  {
    "accountAvatar": "2e6e1b0512aa4d4c8c36221cde76027b.jpg",
    "accountId": "lisi",
    "accountName": "mr.li",
    "associatedId": "zhangsan",
    "companyId": "g09asd3qs3d8s",
    "companyName": "Test Team",
    "createTime": 1709863371382,
    "id": "cv7q7u8rnuksb",
    "remark": "Create account: zhangsan",
    "type": "CreateAccount",
    "updateTime": 1709863371382
  }
]

queryOptLogListCount

Query operation record count

js
informat.system.queryOptLogListCount(filter);

Parameters

ParameterTypeDescription
filterFilterFilter condition

List of fields available in the filter

FieldTypeDescription
typeStringOperation type
accountIdStringUser who performed the operation
remarkStringRemark / Note

Operation type optional values:

Operation TypeDescription
CreateAccountCreate Account
UpdateAccountUpdate Account
RegisterRegister
PasswordLoginUsername & Password Login
WechatLoginWeChat QR-Code Login
MobileNoLoginMobile SMS-Code Login
DingTalkLoginDingTalk Seamless Login
WeWorkLoginWeCom (WeChat Work) Seamless Login
ssoLoginSSO Login
LogoutLogout
UpdateUserNameChange Login Name
UpdateNickNameChange Nickname
UpdateMobileNoChange Mobile Number
UpdateEmailChange Email
SwitchCompanySwitch Team
InviteMemberInvite Member
DeleteMemberRemove Member
CreateDepartmentCreate Department
UpdateDepartmentEdit Department
DeleteDepartmentDelete Department
CreateRoleCreate Role
UpdateRoleEdit Role
DeleteRoleDelete Role
CreateCompanyCreate Team
CompanySetProSet Trial Mode
CompanySetModuleConfigure Modules
CreateAppCreate App
UpdateAppEdit App
DeleteAppDelete App
ArchiveAppArchive App
CreateAppMemberAdd App Member
UpdateAppMemberEdit App Member
DeleteAppMemberRemove App Member
UpdateAppMemberAccessPasswordChange App-Member Access Password
CreateAppModuleAdd App Module
DeleteAppModuleRemove App Module
DeleteRecycleBinEmpty Recycle Bin

Return Value

Type: Integer

Description: Number of operation records

Example

js
let filter = {
  conditionList: [{ fieldId: "type", opt: "eq", value: "CreateAccount" }],
};
informat.system.queryOptLogListCount(filter);
js
6

deleteOptLogList

Batch delete system logs

js
informat.system.deleteOptLogList(filter);

Parameters

ParameterTypeDescription
filterFilterFilter conditions

List of fields available in the filter

FieldTypeDescription
typeStringOperation type
accountIdStringUser who performed the operation
remarkStringRemark / Note
createTimeStringCreation timestamp
updateTimeStringLast update timestamp

Return Value

Type: Integer

Description: Number of operation records deleted

Example

js
let filter = {
    conditionList:[
        {fieldId:'type', opt: 'eq', value: 'CreateAccount'}
    ]
}
informat.system.deleteOptLogList(filter)
js
6

runWithContext

Cross-team and cross-app execution of script functions

js
informat.system.runWithContext(context, func);

Parameters

ParameterTypeDescription
contextRunWithContextContext configuration
funcFunctionFunction to execute

RunWithContext structure:

ParameterTypeDescription
companyIdStringTeam ID, default is current team
appDefineIdStringApplication identifier, default is current app

Return Value

Type: Depends on the function executed

Description: Return value of the executed function

Example

js
const addMember = () => {
    informat.user.addUser(informat.app.userId(), ['admin'])
    return true
}

let context = {
    companyId: 'xxxxxxxxxx',
    appDefineId: 'com.myApp'
}

informat.system.runWithContext(context, addMember)
js
true

uploadFile

Upload local files to shared storage. Note: If a file with the same name exists in the local directory, it will be overwritten

javascript
informat.system.uploadFile(localPath, remotePath);

Parameters

ParameterTypeDescription
localPathStringLocal file path
remotePathStringShared storage path

Return Value

None

Example

javascript
// Upload the avatar file; it must be placed in the public directory.
const localPath = "local.png";
const remotePath = "public/newAvatar.png";
informat.system.uploadFile(localPath, remotePath);
// Update the user avatar to the new avatar file.
informat.system.updateAccount({
  id: "ap1cew2up9ehq",
  avatar: "newAvatar.png",
});

setPasswordRule

Set password rules

javascript
informat.system.setPasswordRule(reg);

Parameters

ParameterTypeDescription
regStringPassword rule (regular expression)

Return Value

None

Example

javascript
// Set the password rule to 7-20 characters, including numbers, letters, and special characters.
informat.system.setPasswordRule("^w{7,20}$");

executeAsync

Execute tasks asynchronously (in a new thread)

javascript
informat.system.executeAsync(func, arg);

Parameters

ParameterTypeDescription
funcFunctionLambda function, cannot be empty
argObjectInput parameter for the function
successCallbackFunctionSuccess callback function, can be empty
failedCallbackFunctionFailed callback function, can be empty

Return Value

None

Example

javascript
function asyncTask(input) {
  console.log("asyncTask start: " + input);
  return informat.table.insert("dataModelBasics", {
    singleText: input,
  });
}

function successCallback(result) {
  console.log("asyncTask result: " + result);
  return informat.table.insert("dataModelBasics", {
    singleText: "success",
  });
}

function failedCallback(exception) {
  console.log("asyncTask exception: " + exception);
  return informat.table.insert("dataModelBasics", {
    singleText: "failed",
  });
}

informat.system.executeAsync(asyncTask, "123", successCallback, failedCallback);

getTokenByAccount

Query login credentials by account ID and type

javascript
informat.system.getTokenByAccount(accountId, type);

Parameters

ParameterTypeDescription
accountIdStringAccount ID
typeStringType, optional values: index, mobile

Return Value AccountToken

Example

javascript
let token = informat.system.getTokenByAccount('zhangsan', 'index');
console.log(token)
json
{
  "accountId": "zhangsan",
  "companyId": "g09aj7cus3d8s",
  "createTime": 1744809507322,
  "dbIndex": 0,
  "expireTime": 1744827749095,
  "token": "b4b5013a483844c7b290808194f58418",
  "type": "index"
}

updateTokenExpireTime

Update login token expiration time

javascript
informat.system.updateTokenExpireTime(token, expireTime);

Parameters

ParameterTypeDescription
tokenStringLogin token
expireTimeDateExpiration time

Return Value None