getQuestionValue( )

为提供的项目路径返回单个问题值。项路径应为整个路径,并且应当包含 visitIdformIditemId 的值。此函数从重复表单和平面表单的问题中提取值。

所有访问不能在变量定义中使用。如果要从单个函数调用中的重复表单实例提取多个值,请使用 getRFValues( ) 函数。

注意:

此规则不支持访问开始日期项。

这是聚合函数,如果目标位于重复表单上,则为每个表单实例运行规则。

语法

getQuestionValue('ruleVariable', eventInstanceNumber, formInstanceNumber, repeatFormNumber)

参数

ruleVariable

变量(从规则编辑器)。

eventInstanceNumber

事件实例编号 / 周期实例编号(可选)。要引用非重复访问,请传递空字符串。

formInstanceNumber

表单实例编号(可选)。要引用非重复形式,请传递空字符串。

repeatFormNumber

重复表单编号(可选)以参考两个部分表单上的项目。

注意:

如果缺少可选参数,则使用实例编号的当前值。

返回值

问题值,如果没有值,则为 NULL。

  • 日期:如果变量是部分日期,则返回的变量值将是 C1Date 对象;如果变量是完整日期,则返回的变量值将是日期对象。

    注意:

    使用日期项时,必须包含空值检查。有关更多信息,请参见示例。

  • 如果未提供可选参数,则从规则目标上下文获取事件实例编号和表单实例编号。

  • 如果变量是选项控件(复选框、单选或下拉列表),则返回的变量值是 JSON 格式的字符串:("[{\"value\":\"3\",\"label\":\"TestLabel\"}]")。可以使用 JSON.parse 或辅助函数 parseChoice 对此进行语法分析。

    • parseChoice(result))
    • JSON.parse(result))

示例 3-95:在 2 部分表单中使用 getQuestionValue

要将 getQuestionValue 用于 2 部分表单的表行中的项,语法为:

getQuestionValue('ruleVariable', eventInstanceNumber, repeatNumber, formInstanceNumber)
// Get a value from an item in a flat form
return (getQuestionValue('text1');
 
 
// Get a value from an item in repeating form instance #1
// Pass an empty string to eventInstance
return (getQuestionValue('text1', '', 1);
 
 
// Get a value from a flat form in unscheduled visit instance #1
// Pass an empty string to eventInstance
return (getQuestionValue('text1', 1, '');
 
 
// Get a date value from a flat form
var res = getQuestionValue('dt1');
if(res !== null) {
  return res.getFullYear();
} else {
  // do nothing
  return;
}
 
 
//In a 2-section form, get a value from Form 2, Table Row 3:
return getQuestionValue('v2', '', 3, 2);