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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create Contact using JQuery in Microsoft Dynamic CRM 2013 Online

(0) ShareShare
ReportReport
Posted on by

Hi

I Create some code

<!DOCTYPE html>
<html lang="en-us">
<head>
<!-- Tittle -->
<title>Rest JQuery Contact Editor </title>
<!-- JQuery -->

<!-- End JQuery -->
<!-- Sample Libraries -->
<script type="text/javascript" src="../ClientGlobalContext.js.aspx"></script>
<script src="Scripts/jquery_1.9.1.min.js"></script>
<script src="Scripts/RESTJQueryContactEditor.js" type="text/javascript"></script>
</head>
<body>

<div id="mainform">
<h2>JQuery Account Form With Validation</h2>
<!-- Required div starts here -->
<form id="form">
<h3>Account Form</h3>
<p id="returnmessage"></p>
<hr/><br/>
<label>Name: <span>*</span></label>
<br/>

<input type="text" id="name" placeholder="Name"/><br/>
<br/>

<label>Email: <span>*</span></label>
<br/>

<input type="text" id="email" placeholder="Email"/><br/>
<br/>

<label>Contact No: <span>*</span></label>
<br/>
<input type="text" id="contact" placeholder="10 digit Mobile no."/><br/>
<br/>

<label>Message:</label>
<br/>
<input type="button" id="submit" value="Save Description"/>
<br/>
<textarea id="Description" placeholder="Description......."></textarea><br/>
<br/>
<input type="button" id="Save Account" value="Save Account"/>
<br/>
</form>
</div>
</body>
</html>

Am not get any result am very new for HTML5 and JQuery please help me regarding thisquery

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    DH kumar CRM Profile Picture
    1,345 on at

    Hi ,

    what is the error you are getting when you use above code.

    In the mean time use this for Sample: Create, retrieve, update, and delete using the OData endpoint with JavaScript and jQuery.

    use this url as a sample- msdn.microsoft.com/.../gg309549.aspx  

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    You can use this function (find in the JQueryContactEditor.js)

    function createRecord(entityObject, odataSetName, successCallback, errorCallback) {

    /// <summary>

    /// Uses jQuery's AJAX object to call the Microsoft Dynamics CRM OData endpoint to

    ///     Create a new record

    /// </summary>

    /// <param name="entityObject" type="Object" required="true">

    /// 1: entity - a loose-type object representing an OData entity. any fields

    ///                 on this object must be camel-cased and named exactly as they

    ///                 appear in entity metadata

    /// </param>

    /// <param name="odataSetName" type="string" required="true">

    /// 1: set -    a string representing an OData Set. OData provides uri access

    ///                 to any CRM entity collection. examples: AccountSet, ContactSet,

    ///                 OpportunitySet.

    /// </param>

    /// <param name="successCallback" type="function" >

    /// 1: callback-a function that can be supplied as a callback upon success

    ///                 of the ajax invocation.

    /// </param>

    /// <param name="errorCallback" type="function" >

    /// 1: callback-a function that can be supplied as a callback upon error

    ///                 of the ajax invocation.

    /// </param>

    //entityObject is required

    if (!entityObject) {

     alert("entityObject is required.");

     return;

    }

    //odataSetName is required, i.e. "AccountSet"

    if (!odataSetName) {

     alert("odataSetName is required.");

     return;

    }

    else

    { odataSetName = encodeURIComponent(odataSetName); }

    //Parse the entity object into JSON

    var jsonEntity = window.JSON.stringify(entityObject);

    //Asynchronous AJAX function to Create a CRM record using OData

    $.ajax({

     type: "POST",

     contentType: "application/json; charset=utf-8",

     datatype: "json",

     url: clientUrl + ODATA_ENDPOINT + "/" + odataSetName,

     data: jsonEntity,

     beforeSend: function (XMLHttpRequest) {

      //Specifying this header ensures that the results will be returned as JSON.            

      XMLHttpRequest.setRequestHeader("Accept", "application/json");

     },

     success: function (data, textStatus, XmlHttpRequest) {

      if (successCallback) {

       successCallback(data.d, textStatus, XmlHttpRequest);

      }

     },

     error: function (XmlHttpRequest, textStatus, errorThrown) {

      if (errorCallback)

       errorCallback(XmlHttpRequest, textStatus, errorThrown);

      else

       errorHandler(XmlHttpRequest, textStatus, errorThrown);

     }

    });

    }

    And in the HTML

    //Create the CRM record

         createRecord(contactObject, "ContactSet", ContactCreateCompleted, ContactCreateFailed);

    Which you can find in the HTML file in the same folder under that SDK folder.

    You just need to construct the contactObject.

  • Suggested answer
    jlattimer Profile Picture
    24,562 on at

    You might try something like this:

    var entity = {};
    entity.FirstName = 'John';
    entity.LastName = 'Smith';
    entity.EMailAddress1 = 'test@test.com';
    
    $.ajax({
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        datatype: 'json',
        url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet",
        data: JSON.stringify(entity),
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader('Accept', 'application/json');
        },
        async: true,
        success: function (data, textStatus, xhr) {
            newEntityId = data.d.ContactId;
        },
        error: function (xhr, textStatus, errorThrown) {
            alert(textStatus + ' ' + errorThrown);
        }
    });

  • Saddamk206 Profile Picture
    777 on at

    This code will helpful:- 

     

    var entity = {};

    entity.name= $('#name').val();

    entity.email= $('#email').val();

    entity.mobile= $('#contact').val();

    $.ajax({

        type: "POST",

        contentType: "application/json; charset=utf-8",

        datatype: "json",

        url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts",

        data: JSON.stringify(entity),

        beforeSend: function(XMLHttpRequest) {

            XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");

            XMLHttpRequest.setRequestHeader("OData-Version", "4.0");

            XMLHttpRequest.setRequestHeader("Accept", "application/json");

        },

        async: true,

        success: function(data, textStatus, xhr) {

            var uri = xhr.getResponseHeader("OData-EntityId");

            var regExp = /\(([^)]+)\)/;

            var matches = regExp.exec(uri);

            var newEntityId = matches[1];

        },

        error: function(xhr, textStatus, errorThrown) {

            Xrm.Utility.alertDialog(textStatus + " " + errorThrown);

        }

    });

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

News and Announcements

Season of Giving Solutions is Here!

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans