Thursday, May 26, 2016

How to set the From and To Default values in Email in MS CRM

function RetrieveTOfromCASE() {
    var regardingObject = Xrm.Page.getAttribute("regardingobjectid");
    if (regardingObject.getValue() != null) {
        //SDK.REST.retrieveRecord(guid,entityname,select query,null,successcallback,errorcallback);
        SDK.REST.retrieveRecord(regardingObject.getValue()[0].id, "Incident", "Title,ContactId", null, successRetrieveEmail, errorHandler);
        
    }
}

function DefaultFROMandTO(GUID, NAME, LOGICALNAME) {
    //Set From Value
    if (Xrm.Page.ui.getFormType() == 1) {
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = "GUID";
        lookupValue[0].name = "NAME(Contact/User/Queue)";
        lookupValue[0].entityType = "ENTITYNAME(Contact/User/Queue)";
        Xrm.Page.getAttribute('from').setValue(lookupValue);

        //Set To Value
        var lookupValue = new Array();
        lookupValue[0] = new Object();
        lookupValue[0].id = GUID;
        lookupValue[0].name = NAME;
        lookupValue[0].entityType = LOGICALNAME;
        Xrm.Page.getAttribute("to").setValue(lookupValue);
    }
}

var successRetrieveEmail = function (results) {
    DefaultTO(results.ContactId.Id, results.ContactId.Name, results.ContactId.LogicalName);
}

function errorHandler(error) {
}

//You need to add CRMSDK for this to work

Get Parent value in Child Record in MS CRM

function GetParentValue() {
//Fetch the case id.
//calling this function on Email form
    var regardingObject = Xrm.Page.getAttribute("regardingobjectid");
    if (regardingObject.getValue() != null) {
        //OData URI to get address information from parent account record
        var oDataURI = Xrm.Page.context.getClientUrl()
            + "/XRMServices/2011/OrganizationData.svc/"
            + "IncidentSet(guid'" + regardingObject.getValue()[0].id + "')"
            + "?$select=Title,ContactId";

        //Asynchronous XMLHttpRequest to retrieve account record
        var req = new XMLHttpRequest();
        req.open("GET", encodeURI(oDataURI), true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.onreadystatechange = function () {
            debugger;
            if (this.readyState == 4 /* complete */) {
                req.onreadystatechange = null; //avoids memory leaks
                if (this.status == 200) {
                    //parse the response string as a JSON object into the successCallback method.
                    //successCallback(JSON.parse(this.responseText).d);
                    //Directly show the alert and assign accordingly to other values
                    alert(JSON.parse(JSON.parse(this.responseText).d.Title));
                }
                else {
                    errorCallback(CaseID);
                }
            }
        };
        req.send();
    }
}

//Call the GetParentValue method on OnLoad. 

Tuesday, October 27, 2015

HTTP 404 in MS CRM

1.    Check if the database is running up
2.    If the database is set to SingleUser by any chance then follow the below steps
    •    Stop all the Microsoft Dynamics CRM Asynchronous Processing Service in the application server
    •    and then go to SQL Server and open the respective database--> check if DB Properties are accessible --> change from properties
3.    If the DB Properties are not accessible just use the below command

    Use DatabaseName
    GO
    Select * from master.sys.sysprocesses Where spid > 50 And dbid=DB_ID (‘DatabaseName’)


    Use TestServer_MSCRM
        kill 69 --spid from the above Query
    Use master;
    GO
    ALTER DATABASE DatabaseName
    SET MULTI_USER;

Data not showing in Advanced Find in CRM

In advanced find we were not able to see the value in some fields but when we open a record then we will be able to see the data.

Then thought of, might be there will be no data in the table. So I checked in the database then we found the solution as unfortunately the data was not there. 

As there are thousands of records in that entity so it was not feasible to open the each record and Save & Close it, just to make the values available in the advanced view.So I tried to troubleshoot the issue in many ways, since it was OnLoad(doing the changes on the form onload and the data in not there in the database) function problem. It was loading the data on form load.
 


Tuesday, October 6, 2015

cannot specify child attribute in the columnset for Retrieve. Attribute: createdbyname

one of the possible solution for this to ensure the fieldname is existing in that particular entity

Can't access Microsoft.Xrm namespace in Visual Studio

The type or namespace name 'Xrm' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Solution:
Double check in your project settings to see which Target Framework you are using. If it is .NET Framework 4 Client Profile try changing it to .NET Framework 4.

provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified

If your facing the below issue in .NET

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Check the connection string in your Config file
 <connectionStrings>
        <add name="Connection" providerName="System.Data.SqlClient"  
             connectionString="Trusted_Connection=Yes;persist security info=False;Integrated Security=SSPI; Data Source=ServerName\SQLExpress;Initial Catalog=databasename" />

 </connectionStrings>

confirm that we have only one "\" in DataSource