web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

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

(0) ShareShare
ReportReport
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>
I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • KRYPTON Profile Picture
    20 on at

    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
    on at

    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
    20 on at

    That is really amazing thank you for amazing help

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans