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)

CRM Rest Builder

(0) ShareShare
ReportReport
Posted on by 5,514

How to add rest builder code into webresource code to retriev data into table??

*This post is locked for comments

I have the same question (0)
  • sandeepc Profile Picture
    5,514 on at

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/sis_teacherents?$select=sis_name,sis_teacherentid,sis_teacherid&$filter=sis_teacherid eq '' and  sis_name eq '' and  sis_teacherentid eq", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

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

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

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var results = JSON.parse(this.response);

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

                   var sis_name = results.value[i]["sis_name"];

                   var sis_teacherentid = results.value[i]["sis_teacherentid"];

                   var sis_teacherid = results.value[i]["sis_teacherid"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    this is the code

  • necsa Profile Picture
    3,455 on at

    Hi,

    You can use CRM Restbuilder. Please, take as reference following links

    github.com/.../CRMRESTBuilder

    carldesouza.com/.../

    stackoverflow.com/.../dynamics-crm-rest-builder-query-for-many-to-many-relationship

  • sandeepc Profile Picture
    5,514 on at

    But i am unable to see the result . what will be the issue how to solve it

  • necsa Profile Picture
    3,455 on at

    What do you want to retrieve Can you give more detail.

  • sandeepc Profile Picture
    5,514 on at

    I have retrieved and executed code . now how do I add that in my HTML dashboard web resource

  • sandeepc Profile Picture
    5,514 on at

    Pls suggest answer any one its an deadline today to submit

  • sandeepc Profile Picture
    5,514 on at

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/sis_teacherents(00000000-0000-0000-0000-000000000000)?$select=sis_teacherentid,sis_teacherid&$expand=sis_sis_teacherent_sis_teacherchangehistoryent_NewTeacher($select=sis_name)", true);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

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

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

    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");

    req.onreadystatechange = function() {

       if (this.readyState === 4) {

           req.onreadystatechange = null;

           if (this.status === 200) {

               var result = JSON.parse(this.response);

               var sis_teacherentid = result["sis_teacherentid"];

               var sis_teacherid = result["sis_teacherid"];

               for (var a = 0; a < result.sis_sis_teacherent_sis_teacherchangehistoryent_NewTeacher.length; a++) {

                   var sis_sis_teacherent_sis_teacherchangehistoryent_NewTeacher_sis_name = result.sis_sis_teacherent_sis_teacherchangehistoryent_NewTeacher[a]["sis_name"];

               }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

  • sandeepc Profile Picture
    5,514 on at

    <html><head>

    <meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta>

      <title></title>

                   <meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta></head>

    <body style="overflow-wrap: break-word;" onfocusout="parent.setEmailRange();"><div class="col-md-3" style="font-family: undefined;">

    <style>

           .loader {

               border: 8px solid #f3f3f3;

               border-radius: 50%;

               border-top: 8px solid #3498db;

               width: 50px;

               height: 50px;

               -webkit-animation: spin 2s linear infinite; /* Safari */

               animation: spin 2s linear infinite;

           }

           /* Safari */

           @-webkit-keyframes spin {

               0% {

                   -webkit-transform: rotate(0deg);

               }

               100% {

                   -webkit-transform: rotate(360deg);

               }

           }

           @keyframes spin {

               0% {

                   transform: rotate(0deg);

               }

               100% {

                   transform: rotate(360deg);

               }

           }

    .record-span:hover {

               cursor: pointer;

               text-decoration-line: underline;

           th {

               background: #666666;

               color: white;

               border: 1px solid white;

           }

           .btn-group {

               width: 100%;

           }

           .btn {

               overflow: hidden !IMPORTANT;

           }

    .btn:hover {

               background-color: #696868 !IMPORTANT;

           }          

           .btn-primary:hover {

            color: #fff;

            background-color:#286090 !IMPORTANT; ;

            border-color: #2e6da4;

           }

           .multiselect {

               width: 100%;

           }

           .multiselect-container {

               width: 100%;

           }

           .btn {

               border-radius: 0px;

           }

    .loader {

               border: 8px solid #f3f3f3;

               border-radius: 50%;

               border-top: 8px solid #3498db;

               width: 50px;

               height: 50px;

               -webkit-animation: spin 2s linear infinite; /* Safari */

               animation: spin 2s linear infinite;

           }

    .param {

               width: 20%;

           }

    </style>

    <script>

           //l_sendReminderObject = new Object();

           //l_sendReminderObject.sis_sendnotification = "True";

           var globalContext = parent.Xrm.Utility.getGlobalContext();

           var baseUrl = globalContext.getClientUrl();

    select=sis_name,sis_teacherent,sis_teacherid&$filter=sis_teacherid eq '' and  sis_name eq '' and  sis_teacherent eq();

    var l_teacher;

           var dataIFrame = parent.document.getElementById("WebResource_Componenta1e3406")

           if (dataIFrame != null) {

               dataIFrame.setAttribute('style', 'border: none !important')

           }

           var dashboardDiv = parent.document.getElementById("dashboardFrameRow");

           if (dashboardDiv != null) {

               dashboardDiv.style.margin = "0px";

           }

           var l_teacher;

           $(document).ready(function () {

               var  l_teacher;

               l_teacherGetObject = new Object();

               availableTeacher = [];

               var l_Teacher;

      l_teacherGetObject = new Object();

    availableTeacher = [];

               availableClass = [];

               var l_teacher;

    l_teacherGetObject.columnSet = "sis_name";

               l_teacherRecord = Api.oData.retrieveMultiple("sis_teacherent", l_teacherGetObject, false);

               l_EmployeeCodeGetObject.columnSet = "sis_name";

               l_teacher = Api.oData.retrieveMultiple("sis_teacherent", l_teacherGetObject, false);

               for (i = 0; i < l_employeecode.length; i++) {

    l_option = document.createElement("option");

                   l_option.text = l_employeeCode[i].sis_name;

                   l_option.value = l_employeeCode[i].sis_name;

                   l_option.selected = l_selectedemployee[l_employeeCode[i].sis_name[];

                   document.getElementById("employee").add(l_option);

               }

                   if (l_employeecode[i].sis_name == null) {

                       continue;

                   }

                   availableEmployeeCode.push({ 'label': l_EmployeeCode[i].sis_name, 'value': l_EmployeeCode[i].sis_name });

               }

               availableEmployeeCode.push({ 'label': "TBA", 'value': "tba" })

    for (i = 0; i < l_teacherRecord.length; i++) {

                   if (l_teacherRecord[i].sis_name == null) {

                       continue;

                   }

                   availableTeacher.push({ 'label': l_teacherRecord[i].sis_name, 'value': l_teacherRecord[i].sis_teacherentid });

               }

               availableTeacher.push({ 'label': "TBA", 'value': "tba" })

    $("#regularTeacher").autocomplete({

                   source: availableTeacher,

                   select: function (event, ui) {

                       $("#regularTeacher").val(ui.item.label); //ui.item is your object from the array

                       $('#regularTeacher')[0].setAttribute('teacherId', ui.item.value);

                       return false;

                   }

               });  

     $("#EmployeeCode").autocomplete({

                   source: availableTeacher,

                   select: function (event, ui) {

                       $("#EmpoyeeCode").val(ui.item.label); //ui.item is your object from the array

                       $('#EmployeeCode')[0].setAttribute('teacher', ui.item.value);

                       return false;

                   }

               });

               $('.multiselect').multiselect();

               $('#loader1').hide();

               $('#parameters').show();

               $('#myTable').DataTable();

               $(".datepicker").datepicker({

                  showAnim: "slide",

                   dateFormat: 'yy-mm-dd'

               });

               $("#effectiveDate").datepicker({

                   showAnim: "slide",

                   minDate:0,

                   dateFormat: 'dd/mm/yy'

               });

           });

           function ShowEmployeeCode {

               Alert.showWebResource("sis_name", 1200, 600, '<label style="color:#337ab7;margin-left: 45%;font-weight: bold;">Update Class Details</label>', [new Alert.button("Cancel"), new Alert.button("Allocate/Update")], $select=sis_name,sis_month&$filter=sis_month eq '' and  sis_name eq '' and  sis_month eq(), null, null);

           }

           function CheckAll() {

               if ($('#checkall').prop("checked")) {

                   Table.$(".checked").prop("checked", true);

               } else {

                   Table.$(".checked").prop("checked", false);

               }

           }

           function CheckValue(p_value) {

               if (!p_value) {

                   return "TBA";

               }

               return p_value;

           }

     var Table = "";

           function searchData() {

              if ($('#checkall').prop("checked")) {

                  $("#checkall").prop("checked", false);

              }

    var selectedEmployeeCode = $("#EmployeeCode"()[0].getAttribute('teacher');

                             if (selectedEmployeeCode != null && $('#EmployeeCode'().val() != "") {

                   if (selectedEmployeeCode == "tba")

                       l_TeacherGetObject.filterUrl = l_TeacherGetObject.filterUrl + "_sis_teacherent_value eq null and ";

                   else

                       l_TeacherGetObject.filterUrl = l_TeacherGetObject.filterUrl + "_sis_name_value eq '" + selectedEmployeeCode + "' and ";

                   l_classGetObject.filterUrl = l_classGetObject.filterUrl + "_sis_teacherent_value eq '" + selectedRegularTeacher + "' and ";

     }

                l_TeacherGetObject.linkEntityUrl = "sis_Class($select=sis_name)";

               l_TeacherGetObject.filterUrl = l_TeacherGetObject.filterUrl + "sis_teacherentid ne null ";

               l_Teacher = Api.oData.retrieveMultiple("sis_Teacherent", l_TeacherGetObject, false);

              if ($("#academicYear").val() != "")

                  l_Teacher = l_Teacher.filter(w=>w.sis_Class._sis_academicyear_value == $("#academicYear").val());

               var l_values = "";

               if (!(selectedEmployeeCode == null && $('#EmployeeCode').val() != "")) {

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

     l_values = l_values + '<td><input type="checkbox" class="checked"class="checked" name="selectrow" id=' + i + ' ></td><td>' + CheckValue(l_Teacher[i]["_sis_month_value@OData.Community.Display.V1.FormattedValue"]) +

                           '</td><td onclick="CheckRow(this)">' + CheckValue(l_EmployeeCode[i]["_sis_name_value@OData.Community.Display.V1.FormattedValue"]) +

                           '</td><td onclick="CheckRow(this)">' + CheckValue(l_EmployeeCode[i]

                   }

               }  

               $('#myTable').dataTable().fnDestroy();

               document.getElementById("tableBody").innerHTML = l_values;

               Table=$('#myTable').DataTable();

               $('#tableContainer').show();

               DataTableGeneric("WebResource_Componenta1e3406");

           }

           function RemoveFilter() {

               ClearParameters("Month", "EmployeeCode");

              var l_Month = new Object();

               l_selectedMonth = { '1': false, '2': true, '3': false };

               l_MonthGetObject.columnSet = "sis_name,sis_month";

               l_MonthGetObject.orderBy = "sis_month";

               var l_Month = Api.oData.retrieveMultiple("sis_month", l_MonthGetObject, false);

               var l_option;

               for (i = 0; i < l_Month.length; i++) {

                   l_option = document.createElement("option");

                   l_option.text = l_Month[i].sis_month;

                   l_option.value = l_month[i].sis_month;

                   l_option.selected = l_selectedMonth[l_Month[i].sis_month];

                   document.getElementById("Month").add(l_option);

               }

               $('#Teacher').multiselect('refresh');

           }

           function CheckRow(event) {

               var isChecked = event.parentElement.getElementsByTagName('input')[0].checked;

               if (isChecked) {

                   event.parentElement.getElementsByTagName('input')[0].checked = false;

                   $('#checkall')[0].checked = false;

                   return;

               }

               event.parentElement.getElementsByTagName('input')[0].checked = true;

           }

           function check(p_value) {

               if (p_value == true)

                   return "Yes";

               else

                   return "No";

           }

           function numberofSelection() {

               return Table.$('input[name="selectrow"]:checked').length;

           }

           function reminder() {

               var idSelector = function () {

                   return this.id;

               };

               var entity = {};

               entity.sis_name= test;

               var idCheckedBox = Table.$('input[name="selectrow"]:checked').map(idSelector).get();

               if (idCheckedBox.length == 0)

                   alert("Please select a Record.");

               else {

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

                       if(l_Teacher[idCheckedBox[i]].sis_name==test){

                           var l_result = Api.oData.updateRecord("sis_teacherent", l_teacher[idCheckedBox[i]].sis_teacherentid, entity, true);

                       }

                   }

               }

           }

           function parentNotification() {

               var idSelector = function () {

                   return this.id;

               };

               var entity = {};

               entity.sis_parentreminder = true;

               var idCheckedBox = Table.$('input[name="selectrow"]:checked').map(idSelector).get();

               if (idCheckedBox.length == 0)

                   alert("Please select a Record.");

               else {

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

                       if(l_Teacher[idCheckedBox[i]].sis_parentreminder==false){

                           var l_result = Api.oData.updateRecord("sis_teacherent", l_teacher[idCheckedBox[i]].sis_teacherentid, entity, true);

                       }

                       //var l_result = Api.oData.updateRecord("sis_teacherent", l_teacher[idCheckedBox[i]].sis_teacherentid, entity, false);

                   }

               }

           }

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

                   var sis_teacherentid = results.value[i]["sis_teacherentid"];

                   //Use @odata.nextLink to query resulting related records

                   var sis_sis_teacherent_sis_scriptracker_CreatedbyTeacher_NextLink = results.value[i]["sis_sis_teacherent_sis_scriptracker_CreatedbyTeacher@odata.nextLink"];

               }

    </script>

                   <div class="col-md-3 param">

                       <label class=" parameter">Month</label>

    <select id="Month" class="form-control" style=" width: -webkit-fill-available;">

                           <option value="1">January</option>

                           <option value="2">February</option>

                           <option value="3">March</option>

                           <option value="4">April</option>

                           <option value="5">May</option>

                           <option value="6">June</option>

                           <option value="7">July</option>

                           <option value="8">August</option>

                           <option value="9">September</option>

                           <option value="10">October</option>

                           <option value="11">November</option>

                           <option value="12">December</option>

                       </select>

                   </div>

                  <div class="col-md-3 param">

                       <label class=" parameter">Employee</label>

                      <select id="Employee" class="form-control" style=" width: -webkit-fill-available;">

                           <option value="1">Praveen kumar</option>

                           <option value="2">Akash Singh</option>

                           <option value="3">Yang Yi</option>

                           <option value="4">Justin Leow</option>

                           <option value="5">Charis Sim</option>

                           <option value="6">Therese Cheng</option>

                           <option value="7">Lee Sue Lynn</option>

                           <option value="8">Shuli Sudderuddin</option>

                           <option value="9">Feodora Tang</option>

                           <option value="10">Phua Kai Ying</option>

                           <option value="11">Pegg Gwi</option>

                           <option value="12">test</option>

                           <option value="13">Constance Lim</option>

                           <option value="14">Shalini Mehta</option>

                           <option value="15">Anna Villarica</option>

                           <option value="16">Reen Ng</option>

                           <option value="17">Cheong Meiyi</option>

                           <option value="18">Yvonne Lim</option>

                           <option value="19">Patrica Wong</option>

                           <option value="20">Lo *** Ying</option>

                           <option value="21">Himanshu Singh</option>

                           <option value="22">Elizabeth Lee</option>

                           <option value="23">Tan Kok Meng</option>

                           <option value="24">Shubham Grover</option>

                           <option value="25">Praveen Kumar</option>

                       </select>

                   </div>

               <div class="col-md-12" style="float: right; margin-bottom: 10px; margin-top: 10px; font-family: undefined;">

                   <div style="float:right;">

                       <button class="btn" style="background:#999999; color :#fff;" onclick="RemoveFilter();">Clear</button>

                        <button class="btn btn-primary" onclick="SearchTeacher();" style="margin-left:10px;">Search</button>

                   </div>

               </div>

    <div class="col-md-12" id="loader1" align="center" style="position:absolute;margin-top:15%;"><div class=""></div></div>

           <div id="tableContainer" style="margin-top: 10px; display: none; font-family: undefined;">

               <table id="myTable" class="table table-bordered table-condensed table-hover" style="font-family: Segoe\000020UI;font-size: small;">

                   <thead>

                       <tr>

                           <th></th>

                           <th>Employee ID</th>

                           <th>Name</th>

                           <th>HR Portfolio</th>

                           <th>Staus</th>

                           <th>Start Date</th>

                           <th>Cessation Date</th>

                           <th>Track</th>

                           <th>No. of working days</th>

                           <th>Expected No. of Classes (Per Week)</th>

                           <th>Expected No. of Classes (Per Month)</th>

                           <th>Days of MC (May)</th>

                           <th>No. of Classes missed Due to MC (May)</th>

                           <th>Days of Leave (May)</th>

                           <th>HNo. of Classes Missed Due to Leave</th>

                           <th>Expected No. of Classes</th>

                           <th>Actual No. of Classes</th>

                           <th>Actual No. of 2T (May)</th>

                           <th>Difference</th>

                           <th>Utilization</th>

                           <th>Utilization Rate</th>

                       </tr>

                   </thead>

                   <tbody id="tbody"></tbody>

               </table>

               <div class=" l_table"></div>

               <div class="col-md-12" style="float:right;margin-top:10px;">

                   <div style="float:right;">

                       <button class="btn btn-primary" onclick="Download()">Download</button>

                   </div>

               </div>          

           </div>

    </div></body></html>

  • sandeepc Profile Picture
    5,514 on at

    how to add first code into second code

  • necsa Profile Picture
    3,455 on at

    Hi Sandeepc,

    First code rename with function name and parameter. You can call any where this function with parameter in your secon code where you want.

    as example and reference please check following link:

    siddiquemahsud.blogspot.com/.../retrive-record-using-web-api.html

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