Thursday, September 13, 2012

Using Odata, Json in CRM 2011

I had this requirement from client who wanted to pull value from a field in one entity A to another field in another  entity B.
Used Odata services with JQuery and Json to bring about the result.

function SelectFee() {
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
    var CRMObject = new Object();
    /////////////////////////////////////////////////////////////
    // Specify the ODATA entity collection
       //TODO get the GUID of the fee selected
    var speakerFeeLookup = Xrm.Page.getAttribute("wsb_speakerfee").getValue();
    if (speakerFeeLookup == null) return;
    var speakerFeeId = speakerFeeLookup[0].id;
    var ODATA_EntityCollection = "/wsb_feeSet?$select=wsb_TotalFee&$filter=wsb_feeId eq guid'" + speakerFeeId + "'";
    /////////////////////////////////////////////////////////////
    // Define attribute values for the CRM object you want created
    //Asynchronous AJAX function to Create a CRM record using OData
    $.ajax({ type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest) {
           
            var defaultFee = data["d"].results;
           defaultfee1 = parseInt(defaultFee[0].wsb_TotalFee);
           

            Xrm.Page.getAttribute('wsb_deffee').setValue(defaultfee1);
            Xrm.Page.getAttribute('wsb_proposedprice').setValue(defaultfee1);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert("failure: " + errorThrown);
        }
    });
}

Friday, May 18, 2012

Principal user is missing prvReadQuery privilege – CRM2011

When you try to access any Entity and  come up with this error
 "Principal user is missing prvReadQuery privilege"
This is because you haven’t given read permission to the View in the Customization entity. Give the proper privileges in the CRM and this exception would be gone.

Friday, February 17, 2012

CRM 2011 Biztalk Sharepoint Integration

Currently architecting on a project which is build upon CRM 2011.
Working on bringing their existing system data information into CRM with Biztalk integration. Sharepoint 2010 is integrated with CRM for their document solutions.

Wednesday, January 18, 2012

Enabling and Disabling custom Buttons in CRM 2011

There is a lot of posts out there explaining this my 2 cents to clear out more doubts.
I have custom buttons(forward and return)  in my form which I need to enable and disable according to the logged in user profile and also cheking the status.
There are basically some steps involved in this.

1.First create a new solution and add the entity you are trying to disable or enable the buttons.
2.Export the solution zip file and extract the files.
3.The custom.xml has to be modified.
4.First search for you entity in the custom xml
5.In Command Definition  enable the Rule ID, here I am enabling the “Forward” and “Return” custom Buttons.
CommandDefinition Id="Mscrm.Isv.fas_travelbudget.Form.Group0.Control1">
  <EnableRules />
  <DisplayRules />
- <Actions>
  <JavaScriptFunction FunctionName="Mscrm_Isv_fas_travelbudget_Form_Group0_Control1_2" Library="$Webresource:fas_travelbudget_ribbon.js" />
  Actions>
  CommandDefinition>

- <CommandDefinition Id="Mscrm.Isv.fas_travelbudget.Form.Group0.Control2">
- <EnableRules>
  <EnableRule Id="Mscrm.Isv.fas_travelbudget.Form.Group0.Control2.EnableRule" />
  EnableRules>
  <DisplayRules />
- <Actions>
  <JavaScriptFunction FunctionName="Mscrm_Isv_fas_travelbudget_Form_Group0_Control2_3" Library="$Webresource:fas_travelbudget_ribbon.js" />
  Actions>
  CommandDefinition>

-
6.In Rule Definition include the Function name “enableForwardButton” and “enableReturnButton” and use the appropriate  web resource.

- &
  DisplayRules>
- <EnableRules>
- <EnableRule Id="Mscrm.Isv.fas_travelbudget.Form.Group0.Control0.EnableRule">
  <CustomRule FunctionName="enableForwardButton" Library="$Webresource:fas_travelbudget_main_library.js" />
  EnableRule>
- <EnableRule Id="Mscrm.Isv.fas_travelbudget.Form.Group0.Control2.EnableRule">
  <CustomRule FunctionName="enableReturnButton" Library="$Webresource:fas_travelbudget_main_library.js" />
  EnableRule>
  EnableRules>
  RuleDefinitions>
7.In Web resource(Library="$Webresource:fas_travelbudget_main_library.js" ) add the following, here we check the status code and also check one of the lookup fields to see if it matches with the "user id".

var forwardButton;
var returnButton;
forwardButton = false;
returnButton = false;


if ((supervisorid == whoamiUserId)  && (Xrm.Page.getAttribute("statuscode").getValue() == 1))
{
      forwardButton = false;
}

if ((supervisorid == whoamiUserId) && (Xrm.Page.getAttribute("statuscode").getValue() == "7"))
{
returnButton = false;
}

8.The zip the modified xml and import it in the solution.