Monday 13 March 2017

WebAPI Retrieve Records



Below is the sample query to get records,

function retrieveRecordsWebAPI(query)
{
try
{
var data;
var serverURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v8.0/" + query, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req.onreadystatechange = function ()
{
if (this.readyState == 4 )
{
req.onreadystatechange = null;
if (this.status == 200)
{
data = JSON.parse(this.response);
}
else
{
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send();
return data;
}
catch (e)
{
Xrm.Page.ui.setFormNotification("Error occured in function : Common.retrieveRecordsWebAPI()" + ".Details : " + (e.description || e.message), "Error");
}
}

Call above function like below,

function getDataUsingWEBAPI()
{
     var cusId = Xrm.Page.getAttribute("customerid").getValue()[0].id;
var columnSet = "?$select=address1_line1,address1_line2";
var query = "accounts" + "(" + cusId.substring(1, 37) + ")" + columnSet;
var response = retrieveRecordsWebAPI(query);
}

MSCRM Early Bound vs Late Bound

Early Bound:

  1. The code generation tool (CrmSvcUtil) creates early-bound entity classes
  2. Each entity (System and Custom) has class.
  3. All attributes and relationships are included in the generated classes. 
  4. When we write  code intelligence support for entity names ,attributes and relationships
  5. No compilation errors of attributes and entities.
  6. Early bound saves compilation time.
  7. We have to generate wrapper class every time to use the newly created entities or new fields
  8. Over network performance is low because of early bound classes are converted to late bound classes.
  9. Code development is faster
  10. compile-time checking of all types so that no implicit casts occur

Late Bound:
  1. Code development is bit slow compared to early bound
  2. Less serialization occurs as entity data is transmitted over a network, which means higher performance
  3. Developer can make spelling mistakes while developing code, which causes run time errors. 
  4. Late binding checks types only when the object is created or an action is performed on the type


Tuesday 11 October 2016

MSCRM 2015, 2016 Business Process Flow Stage Change Automatically Using JavaScript

Hi this is Sudhakar Reddy Chidipudi

Description:

1.         Business process flows to define a set of steps for people to follow to take them to a desired outcome.
2.       These steps provide a visual indicator that tells people where they are in the business process.
In real time scenarios BPF should be moved from one stage to another stage automatically .Below JavaScript does the same.

function moveNextStage(stgName, flowStatus)
{
                try
                {
                                var pollingAttemptsRemaining = 10;
                                var intervalId;
                                intervalId = setInterval(function ()
                                {
                                                pollingAttemptsRemaining -= 1;
                                                if (Xrm.Page.data.process.getActiveStage().getName() != stgName)
                                                {
                                                                clearInterval(intervalId);
                                                }
                                                if (!Xrm.Page.data.entity.getIsDirty() && Xrm.Page.data.process.getActiveStage().getName() == stgName)
                                                {
                                                                if (flowStatus)
                                                                {
                                                                                Xrm.Page.data.process.moveNext(moveResult);
                                                                }
                                                                else
                                                                {
                                                                                Xrm.Page.data.process.movePrevious(moveResult);
                                                                }
                                                                pollingAttemptsRemaining = 0;
                                                                clearInterval(intervalId);
                                                }
                                                if (pollingAttemptsRemaining <= 0)
                                                {
                                                                clearInterval(intervalId);
                                                }
                                }, 200);
                }
                catch (err)
                {
                                Xrm.Page.ui.setFormNotification("Error occured in function : moveNextStage()" + ".Details : " + (e.description || e.message), "ERROR");
                }
}
function moveResult(result)
{}

How to call above function? Use below code
moveNextStage(“Your BPF stage name”, true); //true moves stage forward  .


Have a nice day ............................... :)

Thursday 30 June 2016

MSCRM 2015, 2016 Business Process Flow Stage Change Automatically Using JavaScript

Hi this is Sudhakar Reddy Chidipudi

In real time scenarios BPF should be moved from one stage to another stage automatically .
Below JavaScript does the same.

function moveNextStage(stgName, flowStatus)
{
try
{
var pollingAttemptsRemaining = 10;
var intervalId;
intervalId = setInterval(function ()
{
pollingAttemptsRemaining -= 1;
if (Xrm.Page.data.process.getActiveStage().getName() != stgName)
{
clearInterval(intervalId);
}
if (!Xrm.Page.data.entity.getIsDirty() && Xrm.Page.data.process.getActiveStage().getName() == stgName)
{
if (flowStatus)
{
Xrm.Page.data.process.moveNext(moveResult);
}
else
{
Xrm.Page.data.process.movePrevious(moveResult);
}
pollingAttemptsRemaining = 0;
clearInterval(intervalId);
}
if (pollingAttemptsRemaining <= 0)
{
clearInterval(intervalId);
}
}, 200);
}
catch (err)
{
Xrm.Page.ui.setFormNotification("Error occured in function : moveNextStage()" + ".Details : " + (e.description || e.message), "ERROR");
}
}

function moveResult(result)
{}

How to call above function? Use below code
moveNextStage(“Your BPF stage name”, true); //true moves stage forward  .


Have a nice day ............................... :)

Monday 24 March 2014

MSCRM 2013 Lookup Multi Value Selection

Hi This is Sudhakar Reddy Chidipudi
In my previous post(http://mscrm2011kt.blogspot.in/2012/04/mscrm-2011-lookup-multi-value-selection.html) i have written javascript to select multiple vales from lookup ,but that script does not work for MSCRM 2013.
If you do simple changes to my script ,it works as expected for mscrm 2013.
document.getElementById(“Your lookup Schema Name”+”_i”).setAttribute(“lookupstyle”, “multi”);
and you have to add event hadler to the lookup,in event hander you have to set lookup as multiselect.
I hope this gives an idea.
Have a nice day……………………………
Sudhakar Reddy Chidipudi

Thursday 4 July 2013

Load Json,JQuery from Home page of MSCRM 2011


Hi All,

This is Sudhakarreddy Chidipudi


Now i  will explain how to load Json,JQuery scripts from homepage grid of CRM Entity.
Every ribbon button has Command Definition .We can load the script files from this Command Definition of actions tags.

Below is the example to load the script files form home page grid.

    <CommandDefinition Id="Mscrm.HomepageGrid.SudhakarReddyLoadScripts">
      <EnableRules>
      </EnableRules>
      <DisplayRules>
      </DisplayRules>
      <Actions>
        <JavaScriptFunction FunctionName="$" Library="$webresource:sudhakar_jSon" />
        <JavaScriptFunction FunctionName="$" Library="$webresource:sudhakar_jQuery" />
        <JavaScriptFunction FunctionName="MyTest" Library="$webresource:sudhakar_Functions">
        </JavaScriptFunction>
      </Actions>
    </CommandDefinition>



Have a nice day:)
Sudhakarreddy Chidipudi

Default form data values using QueryString arguments

                                       SudhakarReddy Chidipudi
 
Hi All,

 Sometimes you may have to open a new CRM from using Query String arguments with default values

We can achieve by using extraq parameter in url

1)Set the default Value for Lookup

To open a new record with default values then below syntax you can use,

Below is the example of opening primary contact of account ,

I have a contact with the name of "Sudhakar Reddy Chidipudi".I want to open the account form with the default contact is "Sudhakar Reddy Chidipudi".

https://anjali.crm.dynamics.com/main.aspx?etc=1&pagetype=entityrecord&extraqs=primarycontactid%3D{ Here you have to provide your record id }%26primarycontactidname%3D Name of your record.

%3D Represents equal(=) and %26 represents &.

2)To open the new record with default name

https://anjali.crm.dynamics.com/main.aspx?etc=1&extraqs=name%3DSudhakarReddyChidipudi&pagetype=entityrecord

Have a nice day :)

Sudhakar Reddy Chidipudi