0

我在 SSJS 中有这段代码,我正在做一些字段验证:thisDoc is a NoteXspDocument fld = the name of a field

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.....尝试一下,直到找到一个可行的解决方案,但这似乎不是最佳解决方案。

4

3 回答 3

2

试试instanceof Date.class。你得到的不是检查thisValue底层类的数据类型,而是检查对象本身。

于 2015-09-18T23:21:56.163 回答
1

因为我正在检索的字段几乎可以是我使用的任何内容

var thisValue = thisdoc.getValue(fld);

在确定我拥有什么样的数据时,我遇到了很多麻烦。它可能是一个空日期/数字/字符串所以我做的第一件事就是找出后端数据类型是什么:

var thisItem:NotesItem = thisDoc.getDocument().getFirstItem(fld);
var type:Integer = thisItem.getType()

如果该字段先前已设置,这会有所帮助,但如果它是一个新文档或该字段尚未收到值,它将是类型 1280 或文本,并且可能为 null。所以我的第一个测试是 null 或“”。然后它变得有点困难,因为我需要测试一些值。在我所有的组合框中,我添加了文本“--- 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

然后我在尝试中包装了各种其他数据类型测试,现在我让它工作了。可能是更好的方法,但这有效。

于 2015-09-22T15:52:48.977 回答
0

用于.getItemValue()返回一个向量数组,然后测试数据类型。您还可以尝试.getItemValueString()返回文本字符串或.getItemValueDate()返回.getItemValueDateTime()日期/时间。

由于getItemValue()返回一个数组,因此使用下标获取第一个元素:

var thisValue = thisDoc.getItemValue(fld);
var thisIsDate = (thisValue[0] instanceof Date);
print("Check Text = " + thisValue[0]);
print("Is this a Date ? " + thisIsDate;
于 2015-09-19T05:15:21.247 回答