如何使XPages中的@DbLookup验证另一个数据库中是否存在值? [英] How to make @DbLookup in XPages verify the existence of a value in another database?

查看:55
本文介绍了如何使XPages中的@DbLookup验证另一个数据库中是否存在值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XPage正在使用用户的输入进行@DbLookup,并试图在同一服务器上不同数据库中的视图中查找该值.

I have an XPage that is doing an @DbLookup with a user's input and trying to find that value in a view in a different database yet on the same server.

我已经验证了视图实际上是按第一列排序的,因此@DbLookup友好.以下代码显示在服务器端Javascript OnClick事件处理程序中,用于XPage上的按钮.

I have already verified that the view is in fact sorted by the first column and therefore @DbLookup friendly. The following code below appears in the server-side Javascript OnClick event handler for a button on my XPage.

我的问题是,尝试将lRep的值分配给"firstNameLabel"时发生错误.即使'FirstName'字段下的记录存在键'P301993',lRep也会从dbLookup返回空值.此dbLookup应该找到返回单个"FirstName"结果的结果.但是,不是.

My problem is that the an error occurs when trying to assign the value of lRep to the 'firstNameLabel'. lRep is returning a null value from the dbLookup even though the a record under the 'FirstName' field exists with the key 'P301993'. This dbLookup should be finding a returning a single 'FirstName' result. However, it is not.

var resultLabel = getComponent("firstNameLabel");
var dbName = new Array(@DbName()[0],"UKCSandbox.nsf");
var lRep = @DbLookup(dbName,"customerLookup","P301993","FirstName");
resultLabel.setValue(lRep.toString());

推荐答案

除非您的格式在复制和粘贴中丢失,否则您的代码有缺陷.这不是Java,而是JavaScript.行尾很重要,函数不会作用于对象,而是返回一个值.当您完全匹配一个时,@DbLookup也会返回一个字符串. ,因此检查字符串对您没有帮助.

Unless your formatting was lost in copy and paste, your code has flaws. This is not Java, this is JavaScript. Line endings matter and functions don't act on the object, but return a value. Also @DbLookup returns a string when you have exactly one match, so checking for string doesn't help you.

您的代码应如下所示:

var ukcNumber = Registration.getItemValueString('UKCNumber').toUpperCase();
var resultLabel = getComponent("ukcNumberLabel");
var dbName = @DbName();
dbName[1] = "UKC\\UKCSandbox.nsf";

var lRep = @DbLookup(dbName,"customerLookup",ukcNumber,1);

resultLabel.setValue((lRep) ? "Success" : "Failed");

这对您有用吗?

更新:需要检查的两件事:

Update: 2 things to check:

  • 使用@DbName在同一数据库中进行查找吗?
  • XPages具有与Java代理相同的安全性约束.您在服务器文档中是否具有足够的权限来执行从其他数据库获取价值"?默认为否!

这篇关于如何使XPages中的@DbLookup验证另一个数据库中是否存在值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆