crm 2011 xrm.page.getattribute在有值时返回null(crm 2011 xrm.page.getattribute returns null when there is v

编程入门 行业动态 更新时间:2024-10-26 09:18:54
crm 2011 xrm.page.getattribute在有值时返回null(crm 2011 xrm.page.getattribute returns null when there is value)

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

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

问题是Xrm.Page.getAttribute(creationDateName)在字段上存在值时(该字段未在窗体中显示,但在查找时有值)返回空值。 有趣的是,在我的测试组织中,相同的代码像魅力一样工作,但是当我将其复制并粘贴到生产组织以释放解决方案时,它无法正常工作,这使我很困惑。 任何想法可能发生什么?

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 */ }

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来返回字段中的值。 你的代码只是检查该字段是否存在于页面上。

您还需要知道,在创建模式下,这些值未设置,因此您无法检索它们。 在更新模式下,它们将工作。 所以你需要检查页面是否处于更新模式:

var formType = Xrm.Page.ui.getFormType(); if (formType === 2) // Update { var creationDate = Xrm.Page.getAttribute(creationDateName).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(); }

更多推荐

本文发布于:2023-07-05 08:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1035455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:xrm   page   crm   null   returns

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!