crm 2011 xrm.page.getattribute returns null when there is value

核能气质少年 提交于 2019-12-14 00:26:25

问题


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?


回答1:


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();
}



回答2:


it gives you the attribute not the value..

to get the value you have to write code as below

var creationDateAttr = Xrm.Page.getAttribute(creationDateName);
var valueDateAttr=creationDateAttr.getValue();

OR

var creationDateAttrValue = Xrm.Page.getAttribute(creationDateName).getValue();

hope this will help




回答3:


Silly me, I forgot to add the field I was looking for that's why it return null but thanks to Donal for the answer, actually I was trying to verify if the field was full or was null. Thanks



来源:https://stackoverflow.com/questions/27489835/crm-2011-xrm-page-getattribute-returns-null-when-there-is-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!