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

Xrm service toolkit on view

(0) ShareShare
ReportReport
Posted on by

I have trouble with where I must add XrmServiceToolkit.js and json2.js if I want to use it on button on view. How do I use XrmServiceToolkit on view in CRM 2015?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    MarkR_B Profile Picture
    465 on at

    This works in CRM 2013 but have not tested in 2015.

    So create a web resource file for your button. Within this web resource create the following function

    YOURNAMESPACE.LoadWebResource = function (resource) {

       var httpRequest = null;

       try {

           if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari

               httpRequest = new XMLHttpRequest();

           }

           else { // code for IE6, IE5

               httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

           }

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

           if (serverUrl.match(/\/$/)) {

               serverUrl = serverUrl.substring(0, serverUrl.length - 1);

           }

           httpRequest.open("GET", serverUrl + "/webresources/" + resource, false);

           httpRequest.send(null);

           eval(httpRequest.responseText);

       }

       catch (e) {

           alert("LoadWebResource >> Error loading " + resource + ":\n" + e.description);

       }

    }

    Now create another function in the same web resource like the one displayed below

    YOURNAMESPACE.buttonFunction = function (selectedId) {

       //Load the web resource

       YOURNAMESPACE.LoadWebResource("XrmServiceToolkit.js");

      //ADD CODE HERE THAT USES THE XrmServiceToolkit

      XrmServiceToolkit.Rest.Retrieve(

                       redId,

                       "accountSet",

                       null, "attributename",

                       function (result)

                       {

                           //HANDLE SUCCESS

                       },

                       function (error) {

                           //HANDLE ERROR

                       },

                       false

                   );

    }

    Now attach YOURNAMESPACE.buttonFunction to your button.

    Hope this makes sense and helps at the same time!!

    Mark

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 > 🔒一 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