跳至主要内容
Adaptive Planning
上次更新时间 :2025-11-21
ai.util

ai.util

函数

方法
参数
退货
描述
apply( object, config )
  • obj: Object 属性的接收者
  • config: Object 属性的来源
对象
将 config 的所有属性复制到 obj 并返回 obj。
decodeBase64( encodedBase64 )
2018.3 推出
  • 编码的Base64:字符串
编码为 Base64 的字符串。例如 dGV4dA==
String
返回已解码的 Base64 字符串。
文本框
decodeHtml( encodedHtml )
2018.3 推出
  • encodedHtml: String
一个字符串,其中包含已翻译的保留字符,以便在 HTML 文字中使用。<b>您好[where] <字数>!
String
以原始 HTML 格式返回字符串。
'您好 <b> [where] >words<!'
decodeUrl( encodedUrl )
2018.3 推出
  • encodedUrl:字符串
包含 HTML 编码 URL 的字符串。例如 https%3a%2f%2fwww.example.com%2ffings%2f%3fid%3d123%26more%3dwords%23hash
String
返回具有原始 URL 的字符串。
https://www.example.com/fings/?id=123&more=words#hash
解密(cryptedText)
  • cryptedText:先前由 ai.util.crypt()函数生成的加密字符串。
String
返回解密后的原始纯文本字符串。
ai.util.decrypt()函数可反转加密流程,获取加密字符串(通常是存储的密码或 API 密钥),然后将其转换回原始纯文本格式,以便在自定义云数据源 (CCDS)脚本中使用该字符串对外部系统或 API。
要设置此方法,请先设置 Pretty Good Privacy (PGP) 加密。请参见设置 PGP 加密
encodeBase64( rawBase64 )
2018.3 推出
  • rawBase64:字符串
包含文本的字符串。例如文本框
String
将文本编码为 Base64。
dGV4dA==
encodeHtml( rawHtml )
2018.3 推出
  • rawHtml:字符串
包含原始 HTML 的字符串。例如'您好 <b> [where] >words<!'
String
返回一个字符串,其中包含已翻译的保留字符,以便在 HTML 文字中使用。
<b>您好[where] <字数>!
encodeUrl( rawUrl )
2018.3 推出
  • rawUrl:字符串
具有原始 URL 的字符串。例如 https://www.example.com/fings/?id=123&more=words#hash
String
以编码的 HTML 格式返回原始 URL。
https%3a%2f%2fwww.example.com%2ffings%2f%3fid%3d123%26more%3dwords%23hash
encrypt( textToEncrypt )
  • textToEncrypt:您希望安全加密的纯文本值。这通常是在后续 API 调用中使用的密码或敏感信息。
String
返回输入字符串的加密表示形式。此输出应用于存储或传递敏感凭据,而不是纯文本。
ai.util.crypt()函数将加密算法(由Workday Adaptive Planning平台管理)应用于提供的纯文本字符串。这主要用在自定义云数据源 (自定义云数据源 (CCDS)) 脚本中,用于在凭据作为配置参数存储在集成设置中之前对其进行保护。
要设置此方法,请先设置 Pretty Good Privacy (PGP) 加密。请参见设置 PGP 加密
format ( formatString, arg1, arg2....argN )
  • formatString:String 具有替换标记的字符串。例如“有 {0} 件事情”
  • arg1:String 要替换令牌{0} 的值
  • arg2:字符串等...
String
用于定义标记化字符串,并传递任意数量的参数来替换标记。每个令牌都必须是唯一的,并且必须以 {0}、{1} 等格式递增。
isDate( value )
  • value:“Mixed”要测试的值
Boolean
如果传递的值是 JavaScript Date 对象,则返回 true。
未定义 ( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值为“未定义”,则返回 true。
isDefined( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值不是“未定义”,则返回 true。
isArray( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值是 JavaScript 数组,则返回 true,否则返回 false。
isString( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值是字符串,则返回 true。
isNumber ( value )
  • value:“Mixed”要测试的值
Boolean
如果传递的值是数字且有限,则返回 true。
isBoolean( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值为 true 或 false,则返回 true。
toArray( a, i, j )
数组
isPrimitive( 值 )
  • value:“Mixed”要测试的值
Boolean
如果传递的值为字符串、数字或布尔值,则返回 true。

示例

//Example for ai.util.apply var sourceObj = {department:"Engineering"}; var destObj={}; ai.util.apply(destObj,sourceObj); ai.log.logInfo("Source Properties applied to Destination object: "+JSON.stringify(destObj)); // Source Properties applied to destination object: {department:Engineering} //Example for ai.util.decodeHtml var encodedHtml = "Hello &lt;b&gt; [there] &gt;words&lt;!"; var decodedvalue=ai.util.decodeHtml(encodedHtml); ai.log.logInfo("Decoded HTML is " +decodedvalue); // Decoded HTML is Hello [there] >words //Example for ai.util.encodeHtml var rawHtml = "Hello <b> [there] >words<!"; var encodedvalue=ai.util.encodeHtml(rawHtml); ai.log.logInfo("Encoded HTML is " +encodedvalue); // Encoded HTML is Hello <b> [there] >words<! //Example for ai.util.decodeBase64 var encodedBase64 = "VGhpcyBpcyBhIHNhbXBsZSB0ZXh0IGZvciBlbmNvZGluZw=="; var decodedbasevalue= ai.util.decodeBase64(encodedBase64); ai.log.logInfo("Decoded base64 is: "+decodedbasevalue); //Decoded base64 is:"This is a sample text for encoding" //Example for ai.util.encodeBase64 var rawBase64 = "This is a sample text for encoding"; var encodedbasevalue= ai.util.encodeBase64(rawBase64, ""); ai.log.logInfo("Encoded base64 is: "+encodedbasevalue); //Encoded base64 is:VGhpcyBpcyBhIHNhbXBsZSB0ZXh0IGZvciBlbmNvZGluZw== //Example for ai.util.encodeUrl var rawUrl = "https://docs.postman-echo.com/"; var encodedUrl=ai.util.encodeUrl(rawUrl); ai.log.logInfo("Encoded URL is: "+encodedUrl); //Encoded URL is: https%3a%2f%2fdocs.postman-echo.com%2f //Example for ai.util.decodeUrl var encodedUrl = "https%3a%2f%2fdocs.postman-echo.com%2f"; var decodedUrl=ai.util.decodeUrl(encodedUrl); ai.log.logInfo("Decoded URL is: "+decodedUrl); //Decoded URL is: https://docs.postman-echo.com/ //Example for ai.util.encrypt function testConnection(context) { var message = "-----BEGIN PGP MESSAGE-----" +"Version: GnuPG v2.0.14 (GNU/Linux)" +"Your Message" +"-----END PGP MESSAGE-----"; var text = ai.util.decrypt(message,'myPgp'); ai.log.logInfo("text message", text); return true; } //Example for ai.util.decrypt function testConnection(context) { var text = "Text to encrypt"; var encrypedPgpMessage = ai.util.encrypt(text,'myPgp'); ai.log.logInfo("encrypted message", encrypedPgpMessage ); return true; } //Example for ai.util.format var formatted=ai.util.format('How ar{0} you{1}',"e","?"); ai.log.logInfo("Formatted String is: "+formatted); //How are you? //Example for ai.util.isDate() var d = new Date(); var verifyIfDate=ai.util.isDate(d); ai.log.logInfo("Provided value is: "+verifyIfDate); //Provided value is: true //Example for ai.util.isUndefined var sampleValue; var verifyIfUndefined=ai.util.isUndefined(sampleValue); if (verifyIfUndefined) { ai.log.logInfo("Value is undefined"); } else { ai.log.logInfo("Value is defined"); } //Value is undefined //Example for ai.util.isDefined var sampleValue=6; var verifyIfDefined=ai.util.isDefined(sampleValue); ai.log.logInfo("verifyIfDefined: "+verifyIfDefined) if (verifyIfDefined) { ai.log.logInfo("Value is defined"); } else { ai.log.logInfo("Value is undefined"); } //Value is defined //Example for ai.util.isArray var sampleValue=["a","b"]; var verifyIfArray=ai.util.isArray(sampleValue); if (verifyIfArray) { ai.log.logInfo("Is is an Array"); } else { ai.log.logInfo("Not an Array"); } //It is an array //Example for ai.util.isString var sampleValue="123"; var verifyIfString=ai.util.isString(sampleValue); if (verifyIfString) { ai.log.logInfo("Is is a string"); } else { ai.log.logInfo("Not a string"); } //Example for ai.util.isNumber var sampleValue = {firstName:"Jon", lastName:"Doe"}; var verifyIfNumber=ai.util.isNumber(sampleValue); if (verifyIfNumber) { ai.log.logInfo("Is is a number"); } else { ai.log.logInfo("Not a number. Provided value is of type: "+typeof(sampleValue)); } //Not a number. Provided value is of type: object //Example for ai.util.isBoolean var sampleValue = true; var verifyIfBoolean=ai.util.isBoolean(sampleValue); if (verifyIfBoolean) { ai.log.logInfo("Value is Boolean"); } else { ai.log.logInfo("Not a Boolean. Provided value is of type: "+typeof(sampleValue)); } //Value is Boolean //Example for ai.util.isPrimitive var sampleValue = {firstName:"Jon", lastName:"Doe"}; var verifyIfPrimitive=ai.util.isPrimitive(sampleValue); if (verifyIfPrimitive) { ai.log.logInfo("Provided value is a Primitive Data Type"); } else { ai.log.logInfo("Provided value is not primitive: "+typeof(sampleValue)); } return true;