Showing posts with label MS CRM 2016. Show all posts
Showing posts with label MS CRM 2016. Show all posts

Monday, February 13, 2017

Error : Too many entities enabled for auto created access teams.

Error Log: 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Too many entities enabled for auto created access teams.Detail:
<OrganizationServiceFault xmlns:i="" xmlns="">
  <ErrorDetails xmlns:d2p1="" />
  <Message>Too many entities enabled for auto created access teams.</Message>
  <InnerFault i:nil="true" />
  <TraceText i:nil="true" />

In MS CRM by default you can enable for auto create access teams to Maximum 5 entities. Once this limit reaches you will see above error message.
This limit is specified in MaxEntitiesEnabledForAutoCreatedAccessTeams deployment setting.
You need to update this deployment setting if you have more than 5 entities.

To update you can use Powershell

Add-PSSnapin Microsoft.Crm.PowerShell
$Cred = Get-Credential
$CrmOrgs=Get-CrmOrganizations -serverUrl https://< CRM_Server_Host >
 -Credential $Cred
Get-CrmSetting -SettingType TeamSettings
$set =Get-CrmSetting -SettingType TeamSettings
$set.MaxEntitiesEnabledForAutoCreatedAccessTeams = “6”
Set-CrmSetting -Setting $set
Useful links for PowerShell: 

To Update using SQL
Login to SQL server
Run following query on MSCRM_CONFIG database
select * from DeploymentProperties where ColumnName ='MaxEntitiesEnabledForAutoCreatedAccessTeams'

To Update MaxEntitiesEnabledForAutoCreatedAccessTeams  setting run
update DeploymentProperties set IntColumn = 6 where ColumnName ='MaxEntitiesEnabledForAutoCreatedAccessTeams'

Verify your setting is changed or not using select query.
Now you can able to enable 6th entity for auto create access team. 

Tuesday, February 7, 2017

Add custom portal into online CRM

To add custom portal into online CRM

1.  Go to Admin portal, either from dynamics CRM or directly into Admin portal.

2. Then go to Admin Centers and click on Dynamics 365, as shown below

3. Dynamics 365 Administration Center will be opened in new window. 

4. Click on Applications tab in Administration Center.

5. Select Portal Add-On and click on Manage, new window will be opened to configure portal

6.  Configure your portal, by entering name, portal type (Production / Trail), portal URL. 

7. Then select Dynamics 365 instance

8. Once Dynamic 365 instance selected, you need to select portal language, portal administrator  

When selecting portal administrator 
  •  Portal Administrator must be CRM user with System Administrator role.
  • User added as contact in CRM with Web role "Administrator" 
  • Login to the portal using "Sign in with an external account" option with user CRM credentials. 
9. Then select portal Audience and how portal deployed. 

Portal audience once set for portal cannot be changed later from UI. Portal choices are tailored based on the selection of the audience.

For Partner / Employee audiences, user license required for internal users (customer employees, contactors, agents) dependent on entities exposed.

Depending on audience, we will get different options for portal to be deployed. 

10. Submit your request.

11. After submit and accept page, provisioning begins. You will see following screen

12. Once you accept, portal creation request will be submitted.

 It will take around 30 minutes to complete. After provisioning package installation begins.

13.  Once package installation completed you will see portal details, and you are ready to configure your portal. 

 14. In your CRM instance you will see one area for portal, you can manage your custom portal from there. 

Monday, February 6, 2017

Show CRM entity form to particular Business unit users only

In MS CRM we can enable security role to custom forms, and only selected role users can view that form. When selecting role, all Roles are shown form ROOT business unit, there is no option to get security role from child business units.

In some cases if you want to show custom entity form only for particular business unit users regardless of their role, then need to write custom JavaScript code.

Add following function for entity form, which want to show based on business unit, if users business unit is not allowing to view form, then user will be redirected to other form.

var accountScript = {
    showFormBasedOnBusinessUnit: function () {
        var userId = Xrm.Page.context.getUserId();
        userId = userId.replace("{", "").replace("}", "");
        var req = new XMLHttpRequest();"GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/systemusers(" + userId + ")?$select=_businessunitid_value", false);
        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 businessunitid = result["_businessunitid_value"];
                    var businessunitidname = result["_businessunitid_value@OData.Community.Display.V1.FormattedValue"];
                    if (businessunitidname != "Finance") {
                        var forms = Xrm.Page.ui.formSelector.items.get();
                        for (var i in forms) {
                            var formname = forms[i].getLabel();
                            if (formname == "Information") {

                } else {


Tuesday, November 1, 2016

Use FetchXML to Retrieve Data from MS CRM 2016 using Web API

With Web API in MS CRM, we are retrieve data using FetchXML.
Easy way to construct FetchXML queries are using advanced find in CRM, you can create query in advanced find, add columns, define sorting and then download FetchXML.
Once your FetchXML is ready, you can use this FetchXML in web API to retrieve data from CRM.
Here is sample code for how to execute FetXML and get values from FetchXML result set

ExecuteFetchXML: function () {      
        var accountFetchXML = ['< fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
            '< entity name="account">' +
            '< attribute name="name" />' +
            '< attribute name="accountid" />' +
            '< attribute name="numberofemployees" />' +
            '< attribute name="processid" />' +
            '< attribute name="donotpostalmail" />' +
            '< attribute name="statuscode" />' +
            '< attribute name="statecode" />' +
            '< attribute name="telephone1" />' +
            '< attribute name="ownerid" />' +
            '< attribute name="description" />' +
            '< attribute name="primarycontactid" />' +
            '< attribute name="address1_longitude" />' +
            '< attribute name="exchangerate" />' +
            '< attribute name="createdon" />' +
            '< attribute name="openrevenue" />' +
            '< attribute name="industrycode" />' +
            '< attribute name="shippingmethodcode" />' +
            '< order attribute="name" descending="false" />' +
            '< filter type="and">' +
               '< condition attribute="industrycode" operator="not-null" />' +
            '</ filter>' +
            '< link-entity name="contact" from="contactid" to="primarycontactid" visible="false" link-type="outer" alias="prmContact">' +
               '< attribute name="telephone3" />' +
               '< attribute name="spousesname" />' +
               '< attribute name="ownerid" />' +
               '< attribute name="gendercode" />' +
               '< attribute name="description" />' +
               '< attribute name="createdby" />' +
               '< attribute name="address1_latitude" />' +
               '< attribute name="exchangerate" />' +
               '< attribute name="createdon" />' +
               '< attribute name="annualincome" />' +
             '</ link-entity>' +
           '</ entity>' +
         '</ fetch>'].join('');

        var encodedFetchXML = encodeURIComponent(accountFetchXML);

        var req = new XMLHttpRequest();"GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?fetchXml=" + encodedFetchXML, true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        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) {

            var results = JSON.parse(this.response);
              for (var i = 0; i < results.value.length; i++) {                        
               var accountDetails = results.value[i];

               //Single Line Text
               var nameValue = accountDetails['name'];
               var telephone1Value = accountDetails['telephone1'];

               var accountidValue = accountDetails['accountid'];
               var processidValue = accountDetails['processid'];

               //Whole Number
               var numberofemployeesValue = accountDetails['numberofemployees'];

               //Two Option
               var donotpostalmailValue = accountDetails['donotpostalmail'];
               var donotpostalmailTextValue = accountDetails['donotpostalmail@OData.Community.Display.V1.FormattedValue'];

               //Status Reason
               var statuscodeValue = accountDetails['statuscode'];
               var statuscodeTextValue = accountDetails['statuscode@OData.Community.Display.V1.FormattedValue'];

               var statecodeValue = accountDetails['statecode']; //Status
               var statecodeTextValue = accountDetails['statecode@OData.Community.Display.V1.FormattedValue'];

               var owneridValue = accountDetails['_ownerid_value'];
               var OwnerName = accountDetails["_ownerid_value@OData.Community.Display.V1.FormattedValue"]

               //Multiple Line
               var descriptionValue = accountDetails['description'];

               var primarycontactidValue= accountDetails['_primarycontactid_value'];
               var primarycontactidName = accountDetails['_primarycontactid_value@OData.Community.Display.V1.FormattedValue'];

                  //Floating Point Number
                  var address1_longitudeValue= accountDetails['address1_longitude'];

                  var exchangerateValue = accountDetails['exchangerate'];

                  //Date Time
                  var createdonValue = accountDetails['createdon'];

                  var openrevenueValue = accountDetails['openrevenue'];

                  //Option set
                  var industrycodeValue = accountDetails['industrycode'];
                  var industrycodeTextValue = accountDetails['industrycode@OData.Community.Display.V1.FormattedValue'];

                 //Contact - Linked entity data
                 //Single Line Text
                 var prmContact_telephone3Value = accountDetails['prmContact_x002e_telephone3'];
                 var prmContact_spousesnameValue = accountDetails['prmContact_x002e_spousesname'];

                 var prmContact_owneridValue = accountDetails['prmContact_x002e_ownerid'];

                 //Option set
                 var prmContact_gendercodeValue = accountDetails['prmContact_x002e_gendercode'];
                 var prmContact_gendercodeTextValue = accountDetails['prmContact_x002e_gendercode@OData.Community.Display.V1.FormattedValue'];

                 //Multiple Line
                 var prmContact_descriptionValue = accountDetails['prmContact_x002e_description'];

                 var prmContact_createdbyValue = accountDetails['prmContact_x002e_createdby'];

                 //Floating Point Number
                 var prmContact_address1_latitudeValue = accountDetails['prmContact_x002e_address1_latitude'];

                 var prmContact_exchangerateValue = accountDetails['prmContact_x002e_exchangerate'];

                 //Date Time
                 var prmContact_createdonValue = accountDetails['prmContact_x002e_createdon'];

                 var prmContact_annualincomeValue = accountDetails['prmContact_x002e_annualincome'];

                else {

Remember when using fetchXML query in WEB API
1.      You need to URL encoded FetchXML
2.      With FetchXML you can apply paging by setting page and count attribute of the fetch element.