Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Error : Cannot read properties of null (reading 'lead') while creating new record in lead entity

Posted on by 20
<!DOCTYPE html>
<html>
<head>
<title>Page for XRM WEBAPI Create Record in Student Entity</title>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript">

function create()
{
    var entity = {
        subject : document.getElementById('subject').value,
        companyname : document.getElementById('companyname').value,
        firstname : document.getElementById('firstname').value,
        lastname : document.getElementById('lastname').value,
        msdyn_ordertype : document.getElementById('ordertype').value,
        new_businessname : document.getElementById('businessname').value,
        new_dateofbirth : document.getElementById('dob').value
};

        Xrm.WebApi.createRecord("lead"entity).then(
            function success(result) {
                var newEntityId = result.id;
                xrm.Utility.alertDialog("ID : " + result.id);
            },
            function(error) {
                Xrm.Utility.alertDialog(error.message);
            }
        );
}

</script>
</head>
<body>
<div>
    <h1>Create Record in Student Enitity</h1>
    <p>This is testing page for creating record by XRM.webapi.Create Record for <b>Lead</b> Enitity.</p>
</div>
<div>

<div>
    <h4>Subject</h4>
    <input type="text" id="subject" />
    <br> 

    <h4>Company Name</h4>
    <input type="text" id="companyname" />
    <br> 

    <h4>First Name</h4>
    <input type="text" id="firstname" />
    <br> 

    <h4>Last Name</h4>
    <input type="text" id="lastname" />
    <br> 

    <h4>Business Name</h4>
    <input type="text" id="businessname" />
    <br> 

    <h4>Date of Birth </h4>
    <input type="date" id="dob" />
    <br> 

    <h4>Order Type : 192350000</h4>
    <!---192350000-->
    <input type="number" id="ordertype" />
</div>

<br>    
<input type="button" value="Create Record" onclick="create()"/>
</div>



</body>
</html>
  • KRYPTON Profile Picture
    KRYPTON 20 on at
    RE: Error : Cannot read properties of null (reading 'lead') while creating new record in lead entity

    That is really amazing thank you for amazing help

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error : Cannot read properties of null (reading 'lead') while creating new record in lead entity

    Hi KRYPTON,

    I opened its url and get the same error with yours. Then I find this blog(“Cannot read property ‘’ of null”–Error while calling an action from a WebResource in Dynamics 365 - Xrm.WebApi.execute - Debajit's Power Apps & Dynamics 365 Blog (debajmecrm.com)) and use the following code to test:

    
    
    Page for XRM WEBAPI Create Record in Student Entity
    
    
    
    
    

    Create Record in Student Enitity

    This is testing page for creating record by XRM.webapi.Create Record for Lead Enitity.

    Subject


    Company Name


    First Name


    Last Name


    Business Name


    Date of Birth


    Order Type : 192350000


    And it can work:

    pastedimage1632448587648v1.png

  • KRYPTON Profile Picture
    KRYPTON 20 on at
    RE: Error : Cannot read properties of null (reading 'lead') while creating new record in lead entity

    OMG! what silly mistake I have done.

    Thanks Steve Zhao for this amazing effort.

    just want to know

    is not possible to make this happened directly new webpage. I mean what if i dont want to put web resource inside from.  and try to opened with its url like in my case it is

    krypton.dynamics.com/webresource/create-records.html

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error : Cannot read properties of null (reading 'lead') while creating new record in lead entity

    Hi KRYPTON,

    I have tested your code on my side. When I press F12, I got the error xrm is not defined.

    So you need to change xrm.Utility.alertDialog("ID : " + result.id); to Xrm.Utility.alertDialog("ID : " + result.id);(Spelling mistake)

    After changed this, it can work fine.

    pastedimage1632386113464v1.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans