Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

is it possible to write the javascript code?

(0) ShareShare
ReportReport
Posted on by 2

Hello All Experts,

May i know whether it is possible to fetch a record using ajax call within developers tool by using javascript.

*This post is locked for comments

  • Verified answer
    EmployeeOcta Profile Picture
    EmployeeOcta 2 on at
    RE: is it possible to write the javascript code?

    Hello All Experts,

    Finally i have tried with below code and it's working for me.

    This will help us to write code in debugger console without disturbing the MSCRM.

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

          var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

           var Roles = Xrm.Page.context.getUserRoles();

           var RoleId = Roles[i];

           var selectQuery = "/RoleSet?$top=1&$filter=RoleId eq guid'" + RoleId + "'&$select=Name";

          oDataEndpointUrl += selectQuery;

          var service = new XMLHttpRequest();

         if (service != null) {

         service.open("GET", oDataEndpointUrl, false);

         service.setRequestHeader("X-Requested-With", "XMLHttpRequest");

         service.setRequestHeader("Accept", "application/json, text/javascript, */*");

         service.send(null);

         var retrieved = JSON.parse(service.responseText).d;

         var results = new Array();

         for (var i = 0; i < retrieved.results.length; i++) {

         results.push(retrieved.results[i]);

              }

       console.log(results);

              }

    I believe it will help to others as well.

  • EmployeeOcta Profile Picture
    EmployeeOcta 2 on at
    RE: is it possible to write the javascript code?

    Hello Gopalan,

    Yes the same thing i want.

    i don't want to put any javascript webresource inside the crm .

    rather i directly want to write code inside debugger console.

    but as you said there needs to be ajax context so how can i bring that ajax context there?

  • Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: is it possible to write the javascript code?

    If you want to test a new function which is not available in the current context (Example: the JS Web resource file).

    When debugging (breaking at a break point) the code, open the Console window.

    Now paste the new function and execute.

    After that you can invoke the function by entering the function name in the console.

    This is what you are asking?

  • Suggested answer
    RE: is it possible to write the javascript code?

    Please use Console tab in F12 to write your code while debugging

  • EmployeeOcta Profile Picture
    EmployeeOcta 2 on at
    RE: is it possible to write the javascript code?

    Hello Gopalan,

    can you elaborate a little more.

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: is it possible to write the javascript code?

    You should be able to do this

    As long as you have Ajax library (Example: JQuery) in the context.

    Paste the functions first.

    Then invoke the functions.

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: is it possible to write the javascript code?

    Hi,

       not sure why you would need it. You can run a script in the debugger console, but you would need to add that whole script there (and I never tried to add more than a single function call.. it's a single line input, after all)

      You might add a web resource, create a function that you want to call, and, then, call that function from the console instead..

  • EmployeeOcta Profile Picture
    EmployeeOcta 2 on at
    RE: is it possible to write the javascript code?

    Hello Guys,

    if i simply write

    Xrm.Page.data.entity.getId(); in debugger console it will give me guid of the record.

    likewise  i want to write the whole ajax code within the console and not putting them in the crm as a webresource and want to get the result as i get guid .

    is it possible or not?

    hope you guys understand the question.

  • Suggested answer
    RE: is it possible to write the javascript code?

    Best way to check while debugging isto put the code line in a Watch.

  • EmployeeOcta Profile Picture
    EmployeeOcta 2 on at
    RE: is it possible to write the javascript code?

    Hello Guys,

    i don't want to add any webresource.

    simply i want to write the code within debugger console .

    i hope you guys understand what i am trying to find out.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans