'Xrm.Page.getAttribute(...)' is null or not an object

Jawab 'Xrm.Page.getAttribute(...)' is null or not an object

  • Thursday, April 26, 2012 2:24 PM
     
     

    I keep the following error message:

    <CrmScriptErrorReport>
      <ReportVersion>1.0</ReportVersion>
      <ScriptErrorDetails>
       <Message>'Xrm.Page.getAttribute(...)' is null or not an object</Message>
       <Line>3</Line>
       <URL>/%7B634710467020000000%7D/WebResources/dcc_Housing_Grants_library.js?ver=1594856534</URL>
       <PageURL>/userdefined/edit.aspx?etc=10019&pagemode=iframe&preloadcache=1335450152753</PageURL>
       <Function>dcc_customercontactid_onchange()</Function>
       <CallStack>
        <Function>dcc_customercontactid_onchange()</Function>
        <Function>crmForm_window_onload_handler(eventObj,eventArgs)</Function>
        <Function>anonymousanonymous(){crmForm_window_onload_handler(Xrm.Page.ui)}</Function>
       </CallStack>
      </ScriptErrorDetails>

    When running this on load event code:

    function dcc_customercontactid_onchange()
    {
    lookupContact = Xrm.Page.getAttribute("contactid").getValue();

    Xrm.Page.getAttribute("assigned").setValue(lookupContact);

    Anyone know the problem?

All Replies

  • Thursday, April 26, 2012 2:29 PM
     
     
    Please use the below code you have a syntax error in your code
    function dcc_customercontactid_onchange()
    {
    var lookupContact = Xrm.Page.data.entity.attributes.get("contactid").getValue();
    Xrm.Page.getAttribute("assigned").setValue(lookupContact);
    }

    If you need more information please let me know.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!



  • Thursday, April 26, 2012 2:33 PM
    Moderator
     
     Answered Has Code

    Hi,

    First make sure you are using correct field names.

    Second to set lookup you need to follow below script

    var lookup = new Object();
            
    var lookupValue = new Array();
    
    if(Xrm.Page.getAttribute("contactid").getValue()!=null)
    {
    lookup.id= Xrm.Page.getAttribute("contactid").getValue()[0].id;        
          
    lookup.entityType ="contact";
            
    lookup.name =Xrm.Page.getAttribute("contactid").getValue()[0].name;
    lookupValue[0] = lookup;
            
    Xrm.Page.getAttribute("assigned").setValue(lookupValue);
    }


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked As Answer by JMcCon Thursday, May 10, 2012 3:07 PM
    •  
  • Thursday, April 26, 2012 5:12 PM
     
     Answered

    I saw a similar one. Assuming field names are correct, you might want to try 

    Xrm.Page.ui.controls.get().getAttribute().getValue

    instead of Xrm.Page.getAttribute("contactid").getValue()

    I posted a bit more details here:

    http://gotchahunter.net/2012/04/dynamics-crm-2011-client-side-scripting-getvalue-is-not-always-supported/


    Alex Shlega, GotchaHunter.Net

    • Marked As Answer by JMcCon Thursday, May 10, 2012 3:07 PM
    •  
  • Friday, April 27, 2012 11:27 AM
    Moderator
     
     

    Hello,

    It seems that your custom handler fails. Can you please provide code of dcc_customercontactid_onchange() function from dcc_Housing_Grants_library.js webresource?


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

  • Thursday, May 03, 2012 8:40 AM
     
     

    I meet the simlar question when use Xrm.Page.ui.controls.get('xxx') in form load

  • Thursday, May 10, 2012 3:07 PM
     
     

    I got this sorted.

    I had to ensure there was a default value in the dropdown rather than it being null.