Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create new record from web resource(HTML) with lookup(incident) using JavaScript

Posted on by 480

I want to create new record(entity-name: mb_myEntity) with following fields using JavaScript in html form.

Field logical Name Field Type
mb_name single text
mb_case Lookup

I am unable to created records along with lookup field. Please suggest if i'm doing some mistake, here is the code for creating record

var data =

{

   "mb_name": document.getElementById("name").value,

   "mb_case@odata.bind": "incident(FB4F88B0-XXXX-XX)"

}

parent.Xrm.WebApi.createRecord("mb_myEntity",data).then(

function success(result){

alert(result.id);

},

function (error){}

);

Note: without setting up case lookup, this code is creating new record.

*This post is locked for comments

  • Suggested answer
    Manish Profile Picture
    Manish 480 on at
    RE: Create new record from web resource(HTML) with lookup(incident) using JavaScript

    silly mistake, correcting schema name with your suggested solution solved this issue.

    "mb_case@odata.bind": "/incidents(FB4F88B0-XXXX-XX)"

    replaces with "mb_Case@odata.bind": "/incidents(FB4F88B0-XXXX-XX)"

    Thanks,

    MB

  • Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Create new record from web resource(HTML) with lookup(incident) using JavaScript

    so any error? Can you try CRM REST builder to build your queries & test it.

  • Manish Profile Picture
    Manish 480 on at
    RE: Create new record from web resource(HTML) with lookup(incident) using JavaScript

    thanks for your response, but this solution didn't work for me.

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: Create new record from web resource(HTML) with lookup(incident) using JavaScript

    This should work. Try - "/incidents(FB4F88B0-XXXX-XX)"

    var data =

    {

      "mb_name": document.getElementById("name").value,

      "mb_case@odata.bind": "/incidents(FB4F88B0-XXXX-XX)"

    }

    parent.Xrm.WebApi.createRecord("mb_myEntity",data).then(

    function success(result){

    alert(result.id);

    },

    function (error){}

    );

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans