javascript - crm 2011 xrm.page.getattribute returns null when there is value - Stack Overflow

I'm not really skillful with JScript but I've written the following code within a functionw

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?

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?

Share Improve this question asked Dec 15, 2014 at 17:40 reneh5reneh5 131 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745164576a4614561.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信