locked
CRM 2013: Using Java Script to get multiple records RRS feed

  • Question

  • I have created 2 new entities - "HelpDesk" and "Conversation".

    HelpDesk can have multiple Conversations ( 1 to N relationship)

    HelpDesk unique identifier field is "ID"

    Conversations has 2 attributes  - "modified Date" and "message" . It's referring  attribute to helpdesk is "helpdeskid"

    Now, in the form of HelpDesk - there is a  embed web control (html -js) -  where I would like show the all the "message"  of related  Conversation  ordered by "modified date".

    So, could some one refer me to some simple java script code through which - I can achieve this?

    Thanks,

    Hasib


    Hasibur Rahman

    Friday, April 3, 2015 11:57 PM

Answers

  • Hi,

    You can retrieve entities by using XrmSvcToolkit library ( https://xrmsvctoolkit.codeplex.com/ )

    Here is an example of JS code in a webresource:

    <script id ="XrmSvcToolkit" src="/WebResources/new_XrmSvcToolkit.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    var Functions = {
      Reload: function () {
        var Xrm;
        if (window.parent) { Xrm = window.parent.Xrm; } 
        else if (window.top.frames.opener) { Xrm = window.top.frames.opener.Xrm; }
        if (Xrm != undefined) {
          var HelpDeskID = Xrm.Page.data.entity.getId()
          XrmSvcToolkit.retrieveMultiple({
              entityName: "Conversation",
              async: false,
              odataQuery: "$select=modified_Date,message&" +
                  "$filter=helpdeskid/Id eq (guid'" + HelpDeskID + "'),
              successCallback: function (result) { // result contains all Conversation with helpdeskid = HelpDeskID
                  for (i = 0; i < result.length; i++) {
                      var aaa = result[i]["modified_Date"] + result[i]["message"]  //contains a result entity
                  }
              },
              errorCallback: function (error) {
                  alert(error);
              }
          });
        }
      }
    </script>

    Tuesday, April 7, 2015 1:39 PM
  • Thanks that helped

    Hasibur Rahman

    Tuesday, March 22, 2016 4:27 PM

All replies

  • Hi,

    You can retrieve entities by using XrmSvcToolkit library ( https://xrmsvctoolkit.codeplex.com/ )

    Here is an example of JS code in a webresource:

    <script id ="XrmSvcToolkit" src="/WebResources/new_XrmSvcToolkit.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    var Functions = {
      Reload: function () {
        var Xrm;
        if (window.parent) { Xrm = window.parent.Xrm; } 
        else if (window.top.frames.opener) { Xrm = window.top.frames.opener.Xrm; }
        if (Xrm != undefined) {
          var HelpDeskID = Xrm.Page.data.entity.getId()
          XrmSvcToolkit.retrieveMultiple({
              entityName: "Conversation",
              async: false,
              odataQuery: "$select=modified_Date,message&" +
                  "$filter=helpdeskid/Id eq (guid'" + HelpDeskID + "'),
              successCallback: function (result) { // result contains all Conversation with helpdeskid = HelpDeskID
                  for (i = 0; i < result.length; i++) {
                      var aaa = result[i]["modified_Date"] + result[i]["message"]  //contains a result entity
                  }
              },
              errorCallback: function (error) {
                  alert(error);
              }
          });
        }
      }
    </script>

    Tuesday, April 7, 2015 1:39 PM
  • Thanks that helped

    Hasibur Rahman

    Tuesday, March 22, 2016 4:27 PM