字段及表单规则 - 支持的JavaScript函数

默认情况下,脚本语言为 JavaScript, 我们已经为您添加了jQuery 和 $CS(在全局范围内均可用),因此,允许用户使用  jQuery (v 1.8.3) 和 $CS 库进行编程。 (注意: 使用jQuery访问元素时,不支持 $ 符号)。

$CS 库中可用的Javascript函数

  • $CS.getValue(field) 

    • 使用该函数可以获取指定字段的值。

    • 可以使用它为文本字段设置输入文本

    • 可以使用它为精选列表字段指定选定的项目。

  1. var statusId=$CS.getValue("STATUS"); 

  2. var subject= $CS.getValue("SUBJECT");

  3. var created_date=$CS.getValue("CREATEDDATE");  //This will return a JavaScript Date Object

  4. var additional_hardware=$CS.getValue("RES_3_QUS_3"); //For checkbox type resource fields returns an array of selected resources

 
  • $CS.setValue(field,value) 

    • 使用本函数为指定的字段设置值。

    • 可以使用它为文本字段设置输入文本

    • 可以使用它为精选列表字段指定选定的项目。

  1. $CS.setValue("STATUS","1"); 

  2. $CS.setValue("SUBJECT","test request"); 

  3. $CS.setValue("UDF_DATE1", new Date());

  4. $CS.setValue("RES_3_QUS_3", ["CD RW", "External Harddisk" , "Optical Mouse"]); //Will remove existing selected resources and add this resources for checkbox type resource fields.

 
  • $CS.getText(field

    • 使用本函数获取指定字段的选定项目的文本。

    • 本函数只能使用于精选列表字段。

  1. var status=$CS.getText("STATUS");

 
  • $CS.setText(field,text) 

    • 使用本函数可以为指定的字段设置选定的项目的文本。
    • 本函数只能使用于精选列表字段。
  1. $CS.setText("STATUS","Open");

 
  • $CS.addOptions(field,options)

    • 使用本函数为指定的字段添加选项

    • 这里,options变量应该时一个选项阵列。

    • 本函数只能使用于精选列表字段。 

  1. $CS.addOptions("STATUS",["Open","Closed"]);

 
  • $CS.removeOptions(field,options)

    • 使用本函数从指定的字段中,移除已有的选项内容。

    • 这里,options变量应该时一个选项阵列。

    • 本函数只能使用于精选列表字段。 

  1. $CS.removeOptions("STATUS",["Open","Closed"]);

 
  • $CS.removeAllOptions(fields)

    • 使用本函数从指定的字段,移除所有的已有选项,

    • 这里,fields变量是要移除的字段阵列。

  1. $CS.removeAllOptions(["STATUS"]);   // If all options of status field is removed, new request creation will not work. Since every request should have a status.

  2. $CS.removeAllOptions(["STATUS","PRIORITY"]); 

 
  • $CS.enableField(fields)

    • 使用本函数可以启用一个或多个字段。

    • 这里,fields变量应该是要启用的字段的阵列。

  1. $CS.enableField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.disableField(fields)

    • 使用本函数可以禁用一个或多个字段。只允许用户查看字段,不能编辑相应的字段。

    • 这里,fields变量应该是要禁用的字段的阵列。

  1. $CS.disableField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.hideField(fields)

    • 使用本函数可以隐藏一个或多个字段。限制用户查看相应的字段。

    • 这里,fields变量应该是要隐藏的字段的阵列。

  1. $CS.hideField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.showField(fields)

    • 使用本函数可以显示一个或多个已被隐藏的字段。允许用户查看相应的字段。

    • 这里,fields变量应该是要显示的字段的阵列。

  1. $CS.showField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.mandateField(fields)

    • 使用本函数可以将一个或多个字段设置为必填字段。用户不填写相应字段的值时,不能提交表单。

    • 这里,字段应该是要设置为必填字段的阵列。

  1. $CS.mandateField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.nonMandateField(fields)

    • 使用本函数可以将一个或多个字段设置为非必填字段。这些字段没有值也可以提交表单。      

  1. $CS.nonMandateField(["LEVEL","PRIORITY","URGENCY"]); 

 
  • $CS.stopFormSubmission()

    • 使用本函数停止提交表单。

    • 本函数只适用于“表单提交时”的事件。

  1. var status=$CS.getText("STATUS");

  2. if(status==="Closed")

  3. {

  4. $CS.stopFormSubmission();

  5. }

 
  • $CS.isRequester()

    • 使用本函数,检验登录的用户是否为一个请求人。

    • 如果是请求人,函数返回 True, 否则返回值为False。 

 
  • $CS.isTechnician()

    • 使用本函数,检验登录的用户是否为一个技术员。

    • 如果是技术员,函数返回 True, 否则返回值为False。

 
  • $CS.hasRole(role)

    • 使用本函数,检验登录的用户是否属于指定的角色。

    • 如果登录用户具有指定的角色权限,函数返回 True, 否则返回值为False。

  1. $CS.hasRole("SDAdmin");

 
  • $CS.getLoggedInUserId()

    • 使用本函数获取登录用户的用户ID。 

  1. var userId=$CS.getLoggedInUserId();

 
  • $CS.getLoggedInUserName()

    • 使用本函数获取登录用户的用户名称。

  1. var userName= $CS.getLoggedInUserName();

 
  • $CS.setFieldDependency(dependencyObject)

    • 使用本函数为字段设置依赖关系,

    • 这里依赖对象为两个或三个依赖的对象(JSON对象)

  1. $CS.setFieldDependency(dependencyObject);

 
  • $CS.setTasks(tasksArray)

    • 使用本函数可以设置所给任务ID的阵列。

  1. $CS.setTasks(["templateTask1","templateTask2","templateTask3"]);

 
  • $CS.unSetTasks(tasksArray)

    • 取消设置任务
  1. $CS.unSetTasks(["templateTask1","templateTask2","templateTask3"]);

 
  • $CS.setDescription(description)

    • 设置描述字段的内容。

  1. $CS.setDescription("Application crashes / hangs frequently in user environment causing instability for the system.");

 

$CS.getDescription()

    • 获取描述字段的内容。

  1. var descriptionContent=$CS.getDescription();

 
  • $CS.disableOptions(fieldId,options)

    • 使用该函数可以禁用指定字段的选项。

    • 本函数只适用于精选列表字段。

    • 这里的options变量为选项阵列。
  1. $CS.disableOptions("STATUS",["Open","Closed"]);

 
  • $CS.enableOptions(fieldId,options)

    • 使用该函数可以启用指定字段的选项。

    • 本函数只适用于精选列表字段

    • 这里的options变量为选项阵列
  1. $CS.enableOptions("STATUS",["Open","Closed"]);

 
  • $CS.isVisible(field)

    • 本函数用于检查字段或资源当前是否可视化。

  1. var isPriorityFieldVisiable=$CS.isVisible("PRIORITY");

 
  • $CS.isEnabled(field)

    • 本函数用于检查字段或资源当前是否被启用。

  1. $CS.isEnabled("PRIORITY");

 
  • $CS.isMandated(field)

    • 本函数用于检查字段或资源当前是否是必填项。
  1. $CS.isMandated("PRIORITY");

 

注意: 

如果脚本在执行过程中出错,错误信息在控制台可以看到,它采用如下的格式:

Caught following exception in executing field & form rules script execution of rule:[ Rule name ] at line number: [ line number ] and column:[ column number ] --> Error Message

:

Caught following exception in executing field & form rules script execution of rule:[ check for open request ] at line number: [ 2 ] and column: [ 8 ] --> Uncaught SyntaxError: Unexpected token = .

Back to Top