Saturday 23 December 2017

Custom Approval Process in Dynamics 365 v9 using Java Script


 NOTE: This will work only in V9 and not applicable for earlier version (8.x and below)

With the new JS method Xrm.Navigation.openConfirmDialog & Xrm.Navigation.openAlertDialog given in the XRM object of the dynamics 365 v9, we can customize for approval process without third party library like Alert.JS
For Example, If you want to send an Quote for Approval process and get the outcome(approved/Rejected), then follow the below steps.

1.Create a two buttons 1.Request Approval 2. Approve and an OptionSet (new_ApprovalStatus)with values (1. Approval Requested 2. Approved 3. Rejected).

2.By Setting Display rule, Show “Approve” button upon change of OptionSetValue to “Approval Requested”

3.Upon click on the “Request Approval” button Set the Value to “Approval Requested” using below code



function RequestApproval () {

    debugger;

    Xrm.Page.getAttribute("new_approvalstatus").setValue(100000000);
    Xrm.Navigation.openAlertDialog({text:"Quote Sent for Approval"});

}
  

4.Use the below code for Approval Button.

function ApproveQuote() {

        debugger;

        var ConfirmString = {
            text: "Are you sure want to Approve?",
            title: "Confirmation Alert",
            subtitle:" This Quote is requested for your approval",
            confirmButtonLabel:"Approve",
            cancelButtonLabel: "Reject"
           
        };
        var OptionalParameter = { height: 200, width: 400 };

        Xrm.Navigation.openConfirmDialog(ConfirmString, OptionalParameter).then(

        function (success) {
                if (success.confirmed)
{
        Xrm.Page.getAttribute("new_approvalstatus").setValue(100000001);

        Xrm.Navigation.openAlertDialog({ text: "You Approved the Request" });
}
else
{
       Xrm.Page.getAttribute("new_approvalstatus").setValue(100000002);

       Xrm.Navigation.openAlertDialog({text: "You Rejected the Request" });

}

},

      function(error){

      var ErrorDetails = error.message;

      Xrm.Navigation.openAlertDialog({text:ErrorDetails});
});

}








Hope this helps






Tuesday 12 December 2017

Add Sequence Number to records in SSRS report

While we create report using SSRS report for CRM it is good to should the  sequence number like 1,2,3 .... . you can use the below expression in your S.No column to show auto numbering

Expression:
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")

How to Check CRM instance is online or OnPremise

Most of the time during the troubleshooting we may need to know whether the instance is online or OnPremise. Based on that we may need to go for different troubleshooting methods. So first we need to identify is it online or premise. Here is the simple JS code which you can run on you browser console to identify

var globalContext = Xrm.Utility.getGlobalContext();
 var instance = globalContext.isOnPremises();
Xrm.Navigation.openAlertDialog({ text: instance });// or you can use simple alert method "alert(instance );"



If the result is False - your instance is Online CRM
If it is True - your instance is CRM is on OnPremise