Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to use SDK.REST methods in CRM

Posted on by 55

Hi ,

i know that SDK.REST.js file is present in SDK, but not getting how to make use of it in dynamics crm.   Do we need to create a javascript library and paste all the code present in SDK.REST ?  if we add the library can we directly access using this format [SDK.REST.(methodname)] . or do i need to refferance this SDK.REST library in where ever i use the methods of it??   it will be great help if explain step by step. and some example if possible.

Thanks

*This post is locked for comments

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: how to use SDK.REST methods in CRM

    ReferenceError: Autopopulating is not defined

    This function is not available. Please debug and find out whether this function get invoked. From which you are invoking this?

  • Suggested answer
    ganeshm Profile Picture
    ganeshm on at
    RE: how to use SDK.REST methods in CRM

    onces u added the sdk.rest.js web resource to form properties,based on this lib you can make crud operations like this in separate web resource file,(create record in account)

    function onload()
    {
    var account = {};
    account.Name= "aaa";
    debugger;

    SDK.REST.createRecord(account,"Account", function (account) {alert("created");}, errorHandler );

    }
    function errorHandler(error) {writeMessage(error.message);}

    so this function is called during the onload (onsave,onchange depends on you) once it reach to sdk.rest.createrecord it goes to your sdk.rest.js lib file, which have the definition for the create operations

    //createRecord: function (object, type, successCallback, errorCallback)-

    so you need add the sdk.rest.js file in the form lib section along with the onload.js file.so whatever file you have added in the form lib get loaded to the form page.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to use SDK.REST methods in CRM

    Check for any syntax error in the javascript library containing the function.

    Use this code:

    function Autopopulating()
    {
    var serverUrl = Xrm.Page.context.getClientUrl();
    //mannapur.crm.dynamics.com/.../AccountSet$select=Name,AccountNumber
    var queryUrl = serverUrl + "/XRMServices/2011/Organization.svc/AccountSet?$select=Name,AccountNumber";
    var req = XMLHttpRequest();
    req.open("GET", queryUrl, false);
    req.setRequestHeader("Accept","application/json");
    req.setRequestHeader("Content-Type","application/json; charset=utf-8");
    req.send();
    var results = JSON.parse(req.responseText).d.results;
    if (results != null && results.length > 0)
    {
    }
    }


  • RE: how to use SDK.REST methods in CRM

    Hi ,

    I tried to to execute this code, but getting error is there there anything wrong in this?

    function Autopopulating()

    {

    var serverUrl = Xrm.Page.context.getClientUrl();

    //mannapur.crm.dynamics.com/.../AccountSet$select=Name,AccountNumber

    var queryUrl = serverUrl + /XRMServices/2011/Organization.svc/AccountSet?$select=Name,AccountNumber

    var req = XMLHttpRequest();

    req.open("GET", queryUrl, false);

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

    req.setRequestHeader("Content-Type","application/json; charset=utf-8");

    req.send();

    var results = JSON.parse(req.responseText).d.results;

    if (results != null && results.length > 0)

    {

    }

    }

    Error that m getting is

    : ReferenceError: Autopopulating is not defined

       at eval (eval at RunHandlerInternal (mannapur.crm.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)

       at RunHandlerInternal (mannapur.crm.dynamics.com/.../ClientApiWrapper.aspx)

       at RunHandlers (mannapur.crm.dynamics.com/.../ClientApiWrapper.aspx)

       at OnScriptTagLoaded (mannapur.crm.dynamics.com/.../ClientApiWrapper.aspx)

       at mannapur.crm.dynamics.com/.../ClientApiWrapper.aspx

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: how to use SDK.REST methods in CRM

    Add as a WebResouce, similar to any JavaScript file.

  • Suggested answer
    Dynamics_Alok Profile Picture
    Dynamics_Alok 1,746 on at
    RE: how to use SDK.REST methods in CRM

    Yes..1st Create a Web Resource for SDK.REST.js .

    To use this library you need to add(refer) it on the same Entity form from where you are calling SDK.REST methods.

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: how to use SDK.REST methods in CRM

    Hi Bhargav,

    Yes, you can add the js file directly as web resource and then use method from SDK.REST.

    Please refer here for details:

    msdn.microsoft.com/.../gg334427(v=crm.7).aspx

    arunpotti.wordpress.com/.../restretrieveexample

    Thanks,

    PS

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans