locked
CRM 2011: Xrm.Page.data.entity.attributes.get returning null whilst record has a value RRS feed

  • Question

  • Hi, 

    I have added a new field 'iscollege' to Dynamics CRM 2011 Entity. On form load I am checking the value of 'iscollage' as following:  

    function form_onLoad(context) {     alert(Xrm.Page.data.entity.attributes.get("iscollage"));
    }

    Its returning null, whilst record has a value, in advance search the value of 'iscollage' is 'Yes' 

    Can anyone please help me to figure out the reason.

    Thanks



    Friday, April 26, 2013 9:25 AM

Answers

  • hi,

    i have tested that code snippet which is working fine in my machine.

    make sure the field you are trying to get value is in the form. Not in the unused fields list.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by Ravitheja J Friday, April 26, 2013 9:50 AM
    • Marked as answer by jattscorpion Friday, April 26, 2013 9:56 AM
    Friday, April 26, 2013 9:47 AM
  • Well if it is not on the form, you cannot "catch" the value both ways.

    Bring it on your form and hide the attribute, if you don´t want users to see it. 


    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist, MVP für Microsoft Dynamics CRM

    • Marked as answer by jattscorpion Friday, April 26, 2013 9:56 AM
    Friday, April 26, 2013 9:50 AM

All replies

  • hi,

    try this.

    Xrm.Page.data.entity.attributes.get("iscollage").getValue();

    you code is missing "getValue()" in the end.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    • Edited by Ravitheja J Friday, April 26, 2013 9:32 AM
    • Proposed as answer by Ravitheja J Friday, April 26, 2013 9:34 AM
    • Unproposed as answer by jattscorpion Friday, April 26, 2013 9:42 AM
    Friday, April 26, 2013 9:31 AM
  • Hi,

    and also it seems field name is not correct. prefix is not there like new_ etc.

    Xrm.Page.data.entity.attributes.get("new_iscollage").getValue();


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !


    • Edited by _Vikram Friday, April 26, 2013 9:38 AM
    Friday, April 26, 2013 9:37 AM
  • hi,

    try this.

    Xrm.Page.data.entity.attributes.get("iscollage").getValue();

    you code is missing "getValue()" in the end.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Hi

    Thanks for your reply. I know that. Even if you don't user getValue, in alert it should display [object]. But even if I use: 

    Xrm.Page.data.entity.attributes.get("fieldname").getValue();

    It displays the following error:

    There was an error with this field's customized event.

    Field:window

    Event:onload

    Error:Unable to get value of the property 'getValue': object is null or undefined


    Friday, April 26, 2013 9:38 AM
  • Hi,

    and also it seems field name is not correct. prefix is not there like new_ etc.

    Xrm.Page.data.entity.attributes.get("new_iscollage").getValue();


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !


    Hi, No nothing is wrong with name, I renamed the actual name before boasting it here. Thats why prefix is missing.
    Friday, April 26, 2013 9:40 AM
  • Use Xrm.Page.getAttribute("new_iscollage").getValue();

    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist, MVP für Microsoft Dynamics CRM

    Friday, April 26, 2013 9:45 AM
  • hi,

    i have tested that code snippet which is working fine in my machine.

    make sure the field you are trying to get value is in the form. Not in the unused fields list.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by Ravitheja J Friday, April 26, 2013 9:50 AM
    • Marked as answer by jattscorpion Friday, April 26, 2013 9:56 AM
    Friday, April 26, 2013 9:47 AM
  • Use Xrm.Page.getAttribute("new_iscollage").getValue();

    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist, MVP für Microsoft Dynamics CRM

    I believe, Xrm.Page.getAttribute("new_iscollage").getValue(); is to get the value of form field values. 'isCollage' is not displayed on form. 
    Friday, April 26, 2013 9:48 AM
  • Well if it is not on the form, you cannot "catch" the value both ways.

    Bring it on your form and hide the attribute, if you don´t want users to see it. 


    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist, MVP für Microsoft Dynamics CRM

    • Marked as answer by jattscorpion Friday, April 26, 2013 9:56 AM
    Friday, April 26, 2013 9:50 AM
  • hi,

    i have tested that code snippet which is working fine in my machine.

    make sure the field you are trying to get value is in the form. Not in the unused fields list.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Hi, yes you are right, it's in unused list. I am new to CRM and I was thinking that  Xrm.Page.entity.attributes.get get the value of unused fields as well. While Xrm.Page.getAttribute get the value of used fields. I think I am wrong here. So what I need to do to get the value of unused field?

    Thanks

    Friday, April 26, 2013 9:53 AM
  • For reading values from unused fields through JavaScript.

    1. you need to write retrieve call to get the value.

    2. or you can place field in form and make this field hidden ( double click on field and unmarked visible by default option) then you should be able to read value like

    Xrm.Page.data.entity.attributes.get("new_iscollage").getValue();


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !
    Vikram !

    Friday, April 26, 2013 9:58 AM
  • Hi,

    as per my knowledge, there is no way to retrieve the value of un-used fields.

    small work around is, place the filed in the form but un-check the option "Visible By Default". now field is invisible, and you can retrieve the field value.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, April 26, 2013 9:58 AM