检查 SSJS 中的值
Checking what a value is in SSJS
我在 SSJS 中有这段代码,我正在做一些字段验证:
thisDoc 是一个 NoteXspDocument
fld = 字段名称
var thisValue = thisDoc.getValue(fld);
print("Check Text = " + thisValue);
print("Is is a Date " + (thisValue === Date))
当我 运行 它的日志是这样的:
Check Text = 09/10/15 12:00 PM
Is is a Date false
在这段代码中,我不知道 fld 的数据类型是什么,它是一个字段名。我检查后端文档并获取 NotesItem.Type() 并且此字段在后端的类型为文本 1280,但 NotesXspDocument 有一个日期。我需要确定数据类型是什么 thisValue 确实像 NotesDateTime 对象一样,但我在某处做错了。
我认为问题可能是 NotesDateTime 和 java.util.Date 之间的区别,但它们让我感到困惑。
进一步编辑 --
问题是我有一个字段名称数组 var Fields:Array 然后我循环并得到 fld = Fields[n]
所以当我得到字段的值时它可以是任何文本、日期、数字所以当我做 var thisValue = thisDoc.getValue(fld) or thisDoc.getItemValue(fld)
我需要弄清楚我有什么样的价值。我想我可以尝试 getItem.....
直到找到一个可行的解决方案,但这似乎不是最佳解决方案。
尝试instanceof Date.class
。你得到的不是检查 thisValue
的数据类型与底层 class 的对比,而是检查对象本身。
使用.getItemValue()
到return一个向量数组,然后测试数据类型。您还可以尝试 .getItemValueString()
到 return 文本字符串或 .getItemValueDate()
或 .getItemValueDateTime()
到 return date/time.
由于getItemValue()
return是一个数组,使用下标获取第一个元素:
var thisValue = thisDoc.getItemValue(fld);
var thisIsDate = (thisValue[0] instanceof Date);
print("Check Text = " + thisValue[0]);
print("Is this a Date ? " + thisIsDate;
因为我正在检索的字段几乎可以是我使用的任何内容
var thisValue = thisdoc.getValue(fld);
我在确定我拥有的数据类型时遇到了很多麻烦。它可能是一个 null Date/Number/String 所以我做的第一件事就是找出后端数据类型是什么:
var thisItem:NotesItem = thisDoc.getDocument().getFirstItem(fld);
var type:Integer = thisItem.getType()
如果该字段之前已设置,这会有所帮助,但如果它是一个新文档或该字段尚未收到值,则它将键入 1280 或文本,并且可能为空。
所以我的第一个测试是空值或“”。然后它变得有点困难,因为我需要测试一些值。在我所有的组合框中,我添加了文本“--- Select ??????”作为列表中的第一项,所以我尝试获取“---”的子字符串,但由于数据类型的差异,我需要尝试将其放入:
try{
if (thisValue.substring(0,3) == "---"){
print("have null Prefix");
rtn = false;
errMsg.push("The field " + fld + " is a Required Field please enter a value");
break;
}catch(e){ etc
然后我将各种其他数据类型测试包装在 try 中,现在我可以正常工作了。
可能是更好的方法,但这很有效。
我在 SSJS 中有这段代码,我正在做一些字段验证: thisDoc 是一个 NoteXspDocument fld = 字段名称
var thisValue = thisDoc.getValue(fld);
print("Check Text = " + thisValue);
print("Is is a Date " + (thisValue === Date))
当我 运行 它的日志是这样的:
Check Text = 09/10/15 12:00 PM
Is is a Date false
在这段代码中,我不知道 fld 的数据类型是什么,它是一个字段名。我检查后端文档并获取 NotesItem.Type() 并且此字段在后端的类型为文本 1280,但 NotesXspDocument 有一个日期。我需要确定数据类型是什么 thisValue 确实像 NotesDateTime 对象一样,但我在某处做错了。 我认为问题可能是 NotesDateTime 和 java.util.Date 之间的区别,但它们让我感到困惑。
进一步编辑 --
问题是我有一个字段名称数组 var Fields:Array 然后我循环并得到 fld = Fields[n]
所以当我得到字段的值时它可以是任何文本、日期、数字所以当我做 var thisValue = thisDoc.getValue(fld) or thisDoc.getItemValue(fld)
我需要弄清楚我有什么样的价值。我想我可以尝试 getItem.....
直到找到一个可行的解决方案,但这似乎不是最佳解决方案。
尝试instanceof Date.class
。你得到的不是检查 thisValue
的数据类型与底层 class 的对比,而是检查对象本身。
使用.getItemValue()
到return一个向量数组,然后测试数据类型。您还可以尝试 .getItemValueString()
到 return 文本字符串或 .getItemValueDate()
或 .getItemValueDateTime()
到 return date/time.
由于getItemValue()
return是一个数组,使用下标获取第一个元素:
var thisValue = thisDoc.getItemValue(fld);
var thisIsDate = (thisValue[0] instanceof Date);
print("Check Text = " + thisValue[0]);
print("Is this a Date ? " + thisIsDate;
因为我正在检索的字段几乎可以是我使用的任何内容
var thisValue = thisdoc.getValue(fld);
我在确定我拥有的数据类型时遇到了很多麻烦。它可能是一个 null Date/Number/String 所以我做的第一件事就是找出后端数据类型是什么:
var thisItem:NotesItem = thisDoc.getDocument().getFirstItem(fld);
var type:Integer = thisItem.getType()
如果该字段之前已设置,这会有所帮助,但如果它是一个新文档或该字段尚未收到值,则它将键入 1280 或文本,并且可能为空。 所以我的第一个测试是空值或“”。然后它变得有点困难,因为我需要测试一些值。在我所有的组合框中,我添加了文本“--- Select ??????”作为列表中的第一项,所以我尝试获取“---”的子字符串,但由于数据类型的差异,我需要尝试将其放入:
try{
if (thisValue.substring(0,3) == "---"){
print("have null Prefix");
rtn = false;
errMsg.push("The field " + fld + " is a Required Field please enter a value");
break;
}catch(e){ etc
然后我将各种其他数据类型测试包装在 try 中,现在我可以正常工作了。 可能是更好的方法,但这很有效。