crm 2011 xrm.page.getattribute在有值时返回null [英] crm 2011 xrm.page.getattribute returns null when there is value

查看:207
本文介绍了crm 2011 xrm.page.getattribute在有值时返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JScript并不熟练,但我在函数webResource中编写了以下代码,该函数应该在表单加载时运行(OnLoad)

I'm not really skillful with JScript but I've written the following code within a function webResource that is supposed to run when the form loads (OnLoad)

var creationDateName = "createdon";
var today = new Date();
var creationDateAttr = Xrm.Page.getAttribute(creationDateName);
if(creationDateAttr!=null)
{
  /* Some more code */
}

问题是当字段上有值时,Xrm.Page.getAttribute(creationDateName)返回null(字段没有以表格形式显示但查找时有一个值)。关于它的时髦之处在于,在我的测试组织中,相同的代码就像魅力一样,但当我将其复制并粘贴到生产组织上以发布解决方案时,它无法正常工作,这让我感到很困惑。知道会发生什么吗?

The problem is that Xrm.Page.getAttribute(creationDateName) returns null when there is a value on the field (the field is not being displayed in form but when looking up it has a value). Funky thing about it is that in my test organization the same code worked like a charm, but when I copied and paste it on the production organization to release the solution it doesn't work properly that's what confuses me a lot. Any idea what might be happening?

推荐答案

你需要使用getValue来返回字段中的值。您的代码只是检查页面上是否存在该字段。

You need to use getValue to return the value in the field. Your code is merely checking that the field exists on the Page.

您还需要注意,在创建模式下,这些值未设置,因此您不能检索它们。在更新模式下,它们将起作用。所以你需要检查页面是否也处于更新模式:

You also need to be aware that in Create mode, these values are not set, so you can't retrieve them. In Update mode they will work. So you need to check that the Page is in Update mode too:

var formType = Xrm.Page.ui.getFormType();

if (formType === 2) // Update
{
    var creationDate = Xrm.Page.getAttribute(creationDateName).getValue();
}

这篇关于crm 2011 xrm.page.getattribute在有值时返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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