Display all fields read only in Dynamics CRM Forms


We used javascript to make all fields read only in the MS CRM Forms. We bind the script and on Form "onload event". After "save&Publish" the form.


 function disableAllFields()
 {
   debugger;
    Xrm.Page.ui.controls.forEach(function (control, i) {
    if (control && control.getDisabled && !control.getDisabled()) {
             control.setDisabled(true);
             alert("Hi");
}
        });
 }

we displayed all read only fields in the form

Remove New Registration Process completely from Microsoft CRM Portal


Microsoft CRM Portal allows organizatioon to set up their portal with minimal steps.


When we install the Portal Add-on, the registration process will be enabled by default. The Users can see the 'Registration' page when they click on 'Sign-In ' as shown in below screenshot.

Steps to remove the Registration Process in Microsoft CRM Portal:

Step1: To eliminate the registration process, we can use ‘Authentication/Registration/Enabled’ site setting.
   
  Goto Portals-> Site setting.

Step2: First, we have to create a Site Setting entity record with Name ‘Authentication/Registration/Enabled’ and set the value to false. This setting will completely remove the Registration process from the Portal.



Step3: As seen in the above screenshot, the Register and Redeem Invitation tab has disappeared. 
This setting will not allow users to browse the Register Page URL and the https://<PortalURL>/Account/Login/Register URL is not accessible.

https://<PortalURL>/Register is not accessible.

Restrict portal access by IP address





We want to restrict CRM Portals to run on specific IP Address. So, we can restrict the IP Addresses to open the CRM Portals. We have an in-built  feature available in CRM Portals. Here today i will be taking you through some steps to follow how to restrict the User IP Address to run CRM Portals.


Step1: Goto  Admin Page -> PORTALS

                                    
                              Click on "Manage"

Step2:  It will open the Portal Page.
                        
                           
                     Click on "Set up IP address restriction".

Step3: After clicking on "IP Address restriction". It will open to IP Address.


Click on "+" to add new IP address

Step4:  After adding the IP Address.
                    

Integrate Cafex Live Assistant with Dynamics 365



We have done integration Cafex Live Assistant with Dynamics 365 online instance. So today,we will share you our experience with Cafex Live Assistant. 

Step1:  Open CRM "portal.office.com". Go for administration page. Click on "Live Assistant" to configure with CRM.
 Click on the edit button to configure the Live Assistant.

Step2: After Clicking on Live Assistant then it will ask for email and click on "Submit button" .

After clicking on Submit button. It will display as shown in below screen.
Now, wait for mail response from "Cafex Live Assistant".

Step3: When setup is complete you'll receive a welcome mail from support@liveassistfor365.com with instructions on how to add Live Assist to your website.


Step4: Click on link shown in above screen. It will direct you to Cafex Live Assistant page.
Here in above, it is asking for purchased or trail. Choose your requirement. Trail version will be for 30 days.
This is after integrating Live Assistant in CRM instance occurs, but we need to integrate with end user side also.

Step5:  After choosing, then it directs you to number of users you need to access this Live Assistant.

Step6: Now here we want this Live Assistant to run on Customer Portals. So we need script to integrate this assistant.
We have done like this see the below screen.
In above Screen, follow the steps. To get script and copy the script.

Step7: Make sure that your CRM instance is configured with Customer Service Portals.
We used script in portal templates like shown in below Screen.

We want Live Assistant to be worked on header page of CRM PORTALS. We used that in header template. Save the template.  


Step8: Refresh the Portal page, It will appear like shown below. 


Step9: Start Live chat directly with CRM Users.


In above Screen, Live chat with customer from CRM  USER.
In below Screen, Chat with CRM  USER from Portal. 








Run workflow on ribbon button in Dynamics CRM



To run workflow on ribbon button. follow the below steps:

1. Activate your Workflow and get "ID" of workflow.
2. Prepare new solution with entity and related require components also.
3.Open "Ribbon workbench solution". Select the Solution created by you in which you want to create a new button.
4. Drag the button and drop as per your requirement.
5. Give specific name, create command for that button, etc.
6. Now "enable rules"  for that button. As IS CORE = 'TRUE" by default it will be false.


7.Click on "commad " and add this following as shown in below screenshot.
“/_static/_forms/form.js”
and in the Function Name field= “Mscrm.FormAction.launchOnDemandWorkflowForm“.




8.After that in ribbon workbench click on "Publish". 
Go to CRM instance and refresh the page. Open the respective entity where the Button is created.
9.Based on workflow click on button it will run like this below screenshot. 
10. We have deployed workflow in Ribbon workbench button.





SSRS REPORT FOR CRM ONLINE

Fetchxml using for SSRS REPORT for selected record, prefiltering in Dynamics CRM.


We have used Fetchxml for SSRS report in Dynamic CRM.
In the below code we have used link entity and condition to fetch another entity record details in one report.


<?xml version="1.0"?>
<fetch output-format="xml-platform" distinct="false" version="1.0" mapping="logical">
<entity name="opportunityproduct" >
<attribute name="productid"/>
<attribute name="productdescription"/>
<attribute name="priceperunit"/>
<attribute name="quantity"/>
<attribute name="extendedamount"/>
<attribute name="opportunityproductid"/>
<order attribute="productid" descending="false"/>
<link-entity name="opportunity" link-type="inner" alias="af" from="opportunityid" to="opportunityid">
<attribute name="parentaccountid"/>
</link-entity>
</entity>
</fetch>
<filter type="and">
</filter>

TO PASS PARAMETERS BASED ON SPECIFIC FIELDS

We can also created parameters in SSRS report based on id or specific field in SSRS REPORT.

<?xml version="1.0"?>
<fetch output-format="xml-platform" distinct="false" version="1.0" mapping="logical">
<entity name="opportunityproduct" >
<attribute name="productid"/>
<attribute name="productdescription"/>
<attribute name="priceperunit"/>
<attribute name="quantity"/>
<attribute name="extendedamount"/>
<attribute name="opportunityproductid"/>
<order attribute="productid" descending="false"/>
<link-entity name="opportunity" link-type="inner" alias="af" from="opportunityid" to="opportunityid">
<attribute name="parentaccountid"/>
</link-entity>
</entity>
</fetch>
<filter type="and">
<condition attribute="opportunityid" operator="eq" uiname="test" uitype="opportunity" value="@CRM_Filteredopportunityproduct"/>
</filter>



PARAMETERS:-

Another dataset name is the "CRM_Filteredopportunityproduct". To get link the above parameters in SSRS REPORT.



<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="opportunityproduct">
    <attribute name="opportunityid" />
  </entity>
</fetch>


ON SELECTED RECORDS:-

We can also display SSRS REPORTS on selected record in Dynamic CRM by using  "enableprefiltering="1" "OR "enableprefiltering="true"" OR "enableprefiltering="false"" and
"enableprefiltering="0"".



<?xml version="1.0"?>
<fetch output-format="xml-platform" distinct="false" version="1.0" mapping="logical">
<entity name="opportunityproduct" enableprefiltering="1" prefilterparametername="CRM_Filteredopportunityproduct">
<attribute name="productid"/>
<order attribute="productid" descending="false"/>
<link-entity name="opportunity" link-type="inner" alias="af" from="opportunityid" to="opportunityid">
<attribute name="parentaccountid"/>
</link-entity>
</entity>
</fetch>
</filter>








SSRS REPORT ERROR IN VISUAL STUDIO 2015


Error occurred while preview in visual studio 2015 SSRS Report for Dynamic CRM using fetchxml






We faced this error at report preview in VS 2015. We solved this issue by installing the application called "FiddlerSetup.exe".


 Click on the Tool->Options->Https.

Click on "Protocols" <client>;ssl3;tls1.0 will be displayed. Here now you click on "<client>;ssl3;tls1.0" and add extend like this "<client>;ssl3;tls1.0;tls1.2".
click on "OK".


Note:Allow the credentials to pass click on "YES".


To add Dynamic Charts in CRM Portals

View charts CRM PORTALS

We have approached to get dynamic Charts In CRM Portals through this code. Get The Chart Id and add below code snippet in Portals scripts(To display chart in specific page). 
Refresh the portal page.

Our Code snippet is:

{% chart id:"EE3C733D-5693-DE11-97D4-00155DA3B01E" viewid:"00000000-0000-0000-00AA-000010001006" %}

Add the Dynamic values inside option set through java script in Dynamics 365.

ADD DYNAMIC VALUES IN OPTIONSET

We have a scenario Contact Entity, Test is custom entity. Contact entity has fields like full name and Test entity like contact(option set) is null. We should fill the full name values inside the option set in custom entity. We have approached with ODATA service shown below.

Get contact "fullname" into test entity contact option set field through odata services.

function getcontact()
{
debugger;
//get the contact entity data
var oDataUri = Xrm.Page.context.getClientUrl() +"/xrmservices/2011/OrganizationData.svc/ContactSet?$select=YomiFullName";
      alert(oDataUri);
$.ajax({
type: "GET",
            async: false,
contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataUri,
            beforeSend: function (XMLHttpRequest) {XMLHttpRequest.setRequestHeader("Accept", "application/json");},
            success: function (data, textStatus, XmlHttpRequest) {
alert(data.d.results.length);
//data.d.results.length counts the contact entity total records.
            var i;
for(i=0; i<data.d.results.length; i++)
{
var child= data.d.results[i].YomiFullName;
    Xrm.Page.getControl("new_contact").addOption({value:i , text : child});
            }
           },
            error: function (XMLHttpRequest, textStatus, errorThrown) { alert("error call"); }
        });
}



By using ODATA Services in java script we can achieve only 50 records. if you want to retrieve more than 50 records through ODATA Services use below code.

relatedContact = [];

 if (data && data.d != null && data.d.results != null) {
                Accept(data.d.results);
                fetch(data.d);
            }


function Accept(records) {
    for (var i = 0; i < records.length; i++) {
        relatedContact.push(records[i]);
    }
}

function fetch(records) {
    if (records._next != null) {
        var url = records._next;
        GetRecords(url);
    }
}



To show dialog box in current entity

Dialog box in current entity

If Opportunity is won then show alert box and two buttons "yes or no", if "yes" then get current accountid and open account form. else if "no" then no action taken.

to check whether the Opportunity is won or loss.

function showConfirmDialog() {
debugger;
var statecode = Xrm.Page.getAttribute('statecode').getValue();
//alert(statecode);
if (statecode != null)
{
 // Won
 if (statecode == 1)
  {
     alert("won");
  }
else if(statecode == 2)
 {
   alert("Lost");
 }
 }
}

To perform action based on statecode.
function showConfirmDialog() {
debugger;
var statecode = Xrm.Page.getAttribute('statecode').getValue();
//alert(statecode);
if (statecode != null)
{
 // Won
 if (statecode == 1)
 {
  //alert(statecode);
    Xrm.Utility.confirmDialog("Click Yes or No to set the Personal Notes Value",
        function() {
            //alert("yes");
var currentaccid= Xrm.Page.getAttribute("parentaccountid").getValue()[0].id;
var currentaccname=Xrm.Page.getAttribute("parentaccountid").getValue()[0].name;
//alert(currentaccid);
//alert(currentaccname);
Xrm.Utility.openEntityForm( "account" , currentaccid);
//Xrm.Page.getAttribute("description").setValue("Yes");
        },
        function() {
           // Xrm.Page.getAttribute("description").setValue("No");
   });
 }
}
}

Subgrid access to count the one column and make total

ACCESS SUBGRID TO COUNT THE COLUMN AND SUM

SCENARIO:- Required total of field(priceperunit) in subgrid through javascript

Solution-I had executed below script.

//Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();

      I counted the grid total and based on count i fetched the data of 'priceperunit' data and total all the records present in sub grid.

function CostOfTotal()
{
debugger;
if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("salesorderdetailsGrid") != null && Xrm.Page.getControl("salesorderdetailsGrid") != undefined) {
//if subgrid is not null then counts the grid total
 var count = Xrm.Page.getControl("salesorderdetailsGrid").getGrid().getTotalRecordCount();
 alert("Total Products:"+count);
for(i = 0; i < count; i++) {
//to get control on grid count, which coloum you need to fetch data(like i used priceperunit)
var gridControl = Xrm.Page.getControl('salesorderdetailsGrid').getGrid().getRows().get(i).getData().getEntity().getAttributes().get('priceperunit').getValue();
alert(gridControl );
var cellValue = gridControl;
alert(cellValue);
cellValue = cellValue.replace( /,/,"." );
alert(cellValue);
var sum = sum + parseFloat(cellValue);
alert(sum);
}
}
//to set value in field.
Xrm.Page.getAttribute('new_total').setValue(sum);
}

Currency converter through in Dynamics CRM

To make currency convert into different country currencies in Dynamics CRM. I developed this below javascript.

 function convert(){
debugger;
// YOUR_APP_ID='API_KEY';
 $.ajax({
    url: 'https://openexchangerates.org/api/latest.json?app_id=API_KEY', 
    type: 'POST',
  success: function(data) {
        // exchange rata data is stored in json.quotes
        alert(data.rates.INR);
        // base currency is stored in json.base
        alert(data.base);
        // timestamp can be accessed in json.timestamp
        alert(data.timestamp);

var INR =data.rates.INR;
var USD = data.rates.USD;
var EURO= data.rates.INR;

var txtINR =Xrm.Page.getAttribute("new_inr").getValue();
var txtUSD =Xrm.Page.getAttribute("new_dollar").getValue();
var txtEURO = Xrm.Page.getAttribute("new_euro").getValue();
//from inr to usd and dollar
if(txtINR != null)
{
var val = parseFloat(txtINR).toFixed(2);
//INR to USD
var inrtousd = (1/INR)*val;
alert(inrtousd);
//INR to EURO
var inrtoeuro = (EURO/INR)*val;
alert(inrtoeuro);
break;
}
else if(txtUSD != null)
{
//from usd to inr,euro
var val1 = parseFloat(txtUSD).toFixed(2);
//USD to INR
var ustoinr = val1*INR;
alert(ustoinr);
//USD to EURO
var ustoeuro =val1*EURO;
alert(ustoeuro);
break;
}
else if(txtEURO !=null)
{
//from euro to inr,usd
var val2= parseFloat(txtEURO).toFixed(2);
//EURO TO INR
var eurotoinr = (INR/EURO)*val2;
alert(eurotoinr);
//EURO TO USD
var eurotousd(1/EURO)*val2;
alert(eurotousd);
break;
}
    }
  });
  }

Set maps on entity based on zipcode

Based on user zipcode we can set the location of user in Dynamics CRM.



<html><head>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
function initialize() {
var map_canvas = document.getElementById('map_canvas');
var map_options = {
center: new google.maps.LatLng(-26.4420246,133.281323),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
var geocoder = new google.maps.Geocoder();
var address = window.parent.Xrm.Page.data.entity.attributes.get('address1_composite').getValue();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(12);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
//alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<meta charset="utf-8"></head>
<body style="word-wrap: break-word;">
<div id="map_canvas" style="width: 100%; height: 100%;">google maps</div>
</body></html>

According to Role hide the section

Show Fields on the Basis of Security Role of Current User Using Javascript in MS Dynamics CRM



If you want to show/Hide or Lock/Unlock specific field instead of a whole section you can just replace the "ShowHideSectionAccordingToRole" function with the below function :


function ShowHideFieldAccordingToRole()
{

if(CheckCurrentUserRole("CSR Manager"))
{
//Show the Field
Xrm.Page.ui.controls.get("FieldName").setVisible(true);
               //To UnLock the field
              // Xrm.Page.getControl("FieldName").setDisabled(false); 
}
else 
{
//Hide the Field
Xrm.Page.ui.controls.get("FieldName").setVisible(false);
               //To lockLock the field
              // Xrm.Page.getControl("FieldName").setDisabled(true); 
}
}