Wednesday, 31 July 2019

MS CRM Subgrid Filter Using JavaScript

Hello All ,

Why i am writing this below  Post ,I gone through the different post not found suitable answer for Subgird Filter in MS CRM using Javascript

MS CRM  Version : Dynamics 365 Online v 9.0 

 I am using Form-context instead of Xrm.Page why because it is deprecated in V 9.0

Please find below link to under stand the Form Context.

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/clientapi-form-context


User need check the below check box,to Pass Execution Context


function subgirdFilter(executionContext)
{
var formContext = executionContext.getFormContext(); // get formContext
// Case_Activities is Sub Grid Name
var caseActivities =  formContext.getControl("Case_Activities"); 
    if (caseActivities == null) {
        // Wait one second before recalling the function
        setTimeout(subgirdFilter, 1000);
        return;
    }

var IRCId = formContext.data.entity.getId();
 
  // Build Fetch statement
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  "<entity name='activitypointer'>" +
    "<attribute name='subject' />" +
    "<attribute name='ownerid' />" +
    "<attribute name='activitytypecode' />" +
    "<attribute name='statecode' />" +
    "<attribute name='instancetypecode' />" +
    "<attribute name='community' />" +
    "<attribute name='description' />" +
    "<attribute name='activityid' />" +
    "<order attribute='subject' descending='false' />" +
    "<filter type='and'>" +
      "<condition attribute='isregularactivity' operator='eq' value='1' />" +
      "<filter type='or'>" +
        "<condition attribute='regardingobjectid' operator='eq' uitype='brent_ic_complaintsinformationrequest' value='" + IRCId + "' />" +
      "</filter>" +
    "</filter>" +
    "<link-entity name='email' from='activityid' to='activityid' visible='false' link-type='outer' alias='email_engagement'>" +
      "<attribute name='isemailfollowed' />" +
      "<attribute name='lastopenedtime' />" +
      "<attribute name='delayedemailsendtime' />" +
    "</link-entity>" +
  "</entity>" +
"</fetch>";

  // Update the Subgrid with the new FetchXml and refresh the grid
    if (caseActivities != null)
    {
        caseActivities.getGrid().setParameter("fetchXml",fetchXml);
        caseActivities.refresh();
    }
}

Above code will Work for Filter the "Sub Grid " with Fetch Xml.

Saturday, 3 December 2016

500 Error in Web Service or WebMethod in ASP.net or Asmx calling from Ajax or Js Call.

I got  One issues 500 Error  In Web Service in Asp.net ,I tried different Ways ,I am unable to find exact reason why ? That Reason I writing this Post .

In Browser Developer tools we find following error 500 Internal Server Error


Check the Following steps :-

Step 1:- 

    [System.Web.Script.Services.ScriptService]
    public class firstService : System.Web.Services.WebService
    {

     }

Check that Attribute is Given Above Service or Not .

if not you will get Error. Normally if we create the .asmx File by Default this attribute will be in comment mode ,please  un-comment .

Still issues not Resolved? following next Step 

Step 2:- 


        [ScriptMethod(UseHttpGet = false,ResponseFormat = ResponseFormat.Json)]
        [WebMethod]
        public  static List<employee>  Employee()
        {

          }


Check your placed the following  attribute or not .

[ScriptMethod(UseHttpGet = false,ResponseFormat = ResponseFormat.Json)]

Bydefault  UseHttpGet is false ,you can write like 

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]


Still is Not Resolved ?

Step 3:-  Check the ajax code  what we write  there 


 $.ajax({
            type: "GET", ---->  Type of Call   // 
            url: "/webServices/firstService.asmx/Employee",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (list) {
                $("#Something").append("<ul id='bullets'></ul>");
                for (i = 0; i < list.d.length; i++) {
                    $("#bullets").append("<li>" + list.d[i].name + ":" + list.d[i].age);
                    
                }
            },
            error: function (e) {
                $("#Something").html("There was an error retrieving records");
            }
        });

We Need to Change the Type of Ajax Call.

  type: "GET", ----> // Issue here we need to Change the following line to " POST"

like  this


 $.ajax({
            type: "POST",
            url: "/webServices/firstService.asmx/Employee",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (list) {
                $("#Something").append("<ul id='bullets'></ul>");
                for (i = 0; i < list.d.length; i++) {
                    $("#bullets").append("<li>" + list.d[i].name + ":" + list.d[i].age);
                    
                }
            },
            error: function (e) {
                $("#Something").html("There was an error retrieving records");
            }
        });


NOW issue is Resolved You can able to call [WebMethod] of Service.