String 值方法
Studio 脚本使用标准 JavaScript 字符串方法。String 字段写入文本值,外部入参写入前先归一化。
赋值
const orderNo = String(payload.input.orderNo || '').trim();
await context.form.create({
formApiName: 'orders',
title: orderNo,
data: {
order_no: orderNo,
},
});
可接受入参示例:
| 入参 | 归一化结果 |
|---|---|
' SO-1001 ' | 'SO-1001' |
1001 | '1001' |
null | '' |
常用方法
| 方法 | 用途 |
|---|---|
trim() | 去掉首尾空格 |
toLowerCase() / toUpperCase() | 比较前统一大小写 |
includes(value) | 判断文本是否包含指定内容 |
startsWith(value) / endsWith(value) | 判断前缀或后缀 |
split(separator) | 把分隔文本转成数组 |
replace(search, value) | 替换文本或清理格式 |
padStart(length, value) | 把业务编码补齐到固定长度 |
trim()
写入或比较前去掉首尾空格。
const orderNo = String(payload.input.orderNo || '').trim();
toLowerCase() / toUpperCase()
比较前统一文本大小写。
const email = String(record.data.email || '').trim().toLowerCase();
const isCompanyEmail = email.endsWith('@example.com');
const status = String(payload.input.status || '').trim().toUpperCase();
const isApproved = status === 'APPROVED';
includes(value)
判断字符串是否包含指定内容。
const title = String(record.title || '');
const isUrgent = title.includes('[Urgent]');
startsWith(value) / endsWith(value)
判断前缀或后缀。
const serial = String(record.data.order_no || '');
const isSalesOrder = serial.startsWith('SO-');
const isCompanyEmail = email.endsWith('@example.com');
split(separator)
把分隔文本转成数组。
const tagText = String(payload.input.tags || '');
const tags = tagText
.split(',')
.map((item) => item.trim())
.filter(Boolean);
replace(search, value)
替换文本或清理格式后再使用。
const phone = String(payload.input.phone || '').replace(/\s+/g, '');
const normalizedCode = String(payload.input.code || '').replace(/^order-/i, 'SO-');
padStart(length, value)
把编码补齐到固定长度。
const serial = String(payload.input.serial || '').padStart(6, '0');