Tuesday, September 18, 2018

Order Product Bundle Items


In this post, I am going to describe how to retrieve Sales Order Product items for a particular Product Bundle. If a bundle has 10 products and this bundle is added in sales order lines. This will make 11 sales order lines one header with bundle title and rest as bundle products.
So if we want to get quantity of all bundle items excluding header bundle item then we need to find the relationship and data values insert by Dynamics 365 in backed.
In below plugin, I am demonstrating how to get the bundle item id (sales order line item). Then we can query (fetchxml / query expression) to retrieve all lines having the bundle id in Parent Bundle Id.

Plugin (In this plugin I am showing how to  retrieve bundle id)

using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test.Plugins
{
    public class BundleProductQtyCheck : IPlugin
    {
        bool IsDebug = false;
       
        public void Execute(IServiceProvider serviceProvider)
        {
            IsDebug = false;
            Entity DebugEntity = new Entity("new_plugindebug");
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factory.CreateOrganizationService(context.UserId);
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
           
            string DebugDesc = " Started...";
           
            try
            {

           
               


                string strGcTest = "";
                string NEWLINE = "";
                strGcTest = " Plugin Debug started... at " + DateTime.Now + NEWLINE;
               


                string entityName = "";

                Entity OrderLine = null;
                Entity RetrievedOrderLine = null;
                OrderLine = (Entity)context.InputParameters["Target"];
                entityName = OrderLine.LogicalName;

                if (context.MessageName == "Update")
                {
                    if (OrderLine.Attributes.Contains("shipto_telephone"))
                        return;
                    RetrievedOrderLine = service.Retrieve(OrderLine.LogicalName, OrderLine.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                    if (RetrievedOrderLine.Attributes.Contains("parentbundleid")) {
                        OrderLine["shipto_telephone"] = ((Guid)RetrievedOrderLine["parentbundleid"]).ToString();
                        service.Update(OrderLine);

                    }
                }

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex.InnerException);
                tracingService.Trace(ex.Message);
                if (IsDebug)
                {
                    DebugEntity["new_name"] = this.ToString();
                    DebugEntity["new_description"] = DebugDesc + "\n" + DebugEntity.GetAttributeValue<string>("new_description") + ex.Message + "\n" + ex.ToString();
                    service.Create(DebugEntity);
                }
            }
        }

    }
}








㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤ Ali Hamza Wadood Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn

Tuesday, September 4, 2018

Auto No Dynamics 365 V8.2

I was involved in project using Microsoft Dynamics 365 V8.2. I downloaded the auto number solution, one available for Dynamics CRM 2016 and previous releases. This solution was working fine on previous versions but on Dynamics 365 V8.2, there was error using this solution. I searched and tried to find some alternatives but was not able to find any one. So I thought to develop my own Auto-Number utility / solution for Microsoft Dynamics 365 V8.2.

Below are screen shots for the entity holding configurations for auto number.


At this time Auto No Length is fixed to 5. I will make that dynamic later. Below are details of configuration
Name: Put whatever name you want
Auto No Length: Put 5 (Fix at this time)
Auto No Value: Put value from where you want auto no to increment (First number is 0)
Entity Name: Name of entity
Mapping Field: Field schema name which will hold the auto number value
Prefix / Sufix: Will update in next versions
Zero Pad: Currently zeros are displayed with length of 5 i.e. for number 1 four zeros will be added. This is not changeable int current version

Currently Plugin is also not dynamic (Based on configuration value to fire plugin). Customization Consultant / Developer has to manually register plugin for desired entity and message.

Below is plugin step screen shot.























This is Auto No Solution for Dynamics 365 V8.2 (Uploading soon....)


㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤ Ali Hamza Wadood Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn

Monday, September 3, 2018

Web API Invoke Roll up Field Update

In this post I am sharing the solution to requirement of updating Roll up field using Web API.

Tested on: Dynamics 365 V9.0 Online
Entity Name = new_projects
Field Name = new_totalactualduration


function UpdateRollUp(){
var id ="";
var url = "https://WebAPIAddress/api/data/v9.0/CalculateRollupField(Target=@tid,FieldName=@field)?@tid={%27@odata.id%27:%27new_projects()%27}&@field=%27new_totalactualduration%27"

}




㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤ Ali Hamza Wadood Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn

Check User Specific Role - Web API (1 API Call) - Dynamics CRM 365

I was working in a requirement where ribbon customization was required based on user role. Many ribbon buttons were hidden / visible based on different roles assigned to user. There was also custom button on ribbon bind with custom JavaScript function.

 Due to more buttons bind with Enable Rules to set their visibility result in slow page load and increase user wait for Ribbon Buttons.

Previously, I was getting user roles ids from XRM method and then checking the name of roles by getting role name through Web API retrieve request and passing guid of role as parameter. This means if there are 7 roles assigned to user then system will make 7 API Calls.
Also on custom button trigger, System was again loading the webresource and as API Calls were made outside any function therefore system also made API Calls before triggering custom ribbon button function. There were separate web resource for Enable Rules of Ribbon Buttons. There were methods which were used in Entity Main web resource and in Enble Rules web resource.
What I did was that I create another web-resource and write a class of Dynamics CRM Roles. This class contain method and an array to load all roles from Dynamics CRM 365. So I loaded the array with role name and role guid using the Web API retrieve request for roles. This technique loaded the array with all roles and made the API Call only once.
Now in my logic and other areas where I was checking with role name whether user is assigned that or not, I was using the roles array to match.
So this result in making Web API Call only once.

Here is my code logic.

Updating shortly ....






㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC) LinkedIn

Custom Workflow to send Email to All Team members

There was a requirement in project to send email to all Team members of a certain Queue, whenever a new item is added to that Queue.
To achieve this requirement, I have developed custom workflow so that configuration can be done from the Dynamics Workflow interface / window.

Below is Dynamics Workflow screen
For Beginners: Solution -> Processes -> Create New Process as workflow



















































Saturday, March 31, 2018

Check User Specific Role - Web API - Dynamics CRM 365

In this post, I am going to demonstrate how to check that current logged in user has specific role or not in Dynamics CRM 365 using JavaScript & Web API.


function IsRoleExist(RoleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
        if (GetRoleName(userRoleId) == RoleName) {
            return true;
        }
    }
    return false;

}

function GetRoleName(RoleId) {
    var select = "roles(" + RoleId + ")?$select=name";

    var result = AWXRM.WebAPISelectVersion(select, "8.2");
    var Rolename = result["name"];
    return Rolename;

}

function OnLoad() {

var Role_Admin = "System Admin_1";
var IsRoleExist = null;

   if (IsRoleExist(Role_Admin))
            IsRoleExist = true;
        else
            IsRoleExist = false;
}

Dependency:
Need this library to be included in form load / page load
AWXRMLibrary


㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn



Enable Rule for Default Buttons - Ribbon Workbench - Dynamics CRM 365


1) Install Ribbon Workbench from here
2) Import solution in your Dynamics CRM 365 instance
3) A button "RIBBON WORKBENCH 2016" is created in Solution Page. Click on it
























4) Now new window is opened. Select your desired solution containing entity to be customized. It is better to create a separate solution to be used for ribbon customization and contains only desired entity. In this scenario I have created a new solution "Ribbon Solution" contain only Case entity. Here I am selecting solution Ribbon Solution

























5) Now solution is opened in ribbon workbench. Select your desired entity and on button right mouse click. Now select Customize Command. (In my case as button is already customized therefore this command is shown disabled)























6) Now in command section, select the generated command and click on Add Enable Rule. Now select Add New Enable Rule.




























7) Now click on Add Step & select CustomRule. There are others rules to apply enable rules on button. Here I am only showing the CustomRule.























Friday, March 30, 2018

Object Oriented Javascript - Dynamics CRM 365

I have done lot of work using javascript in Dynamics 365 (CRM) / CRM Projects. During many routine tasks I always used to think about how to optimize my code?, so able to do more with less code. Therefore achieve code reuse-ability, extensiveness and object oriented style. In below Javascript technique I am trying to demonstrate this approach.






function Customer() {

    this.name =  AWXRM.GetXRMAttributeGetVal("name");
    this.custid = AWXRM.GetXRMAttributeGetVal("accountnumber");
    this.address = AWXRM.GetXRMAttributeGetVal("wtr_plot");
    this.customertype = AWXRM.GetXRMAttributeGetText("wtr_customertype");
    this.cnic = AWXRM.GetXRMAttributeGetVal("wtr_cnic");
    this.phone = AWXRM.GetXRMAttributeGetVal("telephone2");
    this.cell = AWXRM.GetXRMAttributeGetVal("telephone1");
    this.guid = Xrm.Page.data.entity.getId();
    this.guidplan = this.guid.replace("{", "");
    this.guidplan = this.guid.replace("}", "");
    this.invoices = {};
    this.invoices.invoicedetails = {};

}

function OnSave(){

   var customer = new Customer();

}




㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn

Saturday, March 24, 2018

Calling REST Web Service in Plugin


I was involved in a project where I have to consume REST Web services to integrate with Dynamics CRM 2016. Below plugin was used to perform this operation.

The web service used POST operation. and retrieved a specific authentication string present in response headers.



























Wednesday, January 17, 2018

Custom Workflow vs Plugin


Workflow / Custom Workflow:
1) Can be triggered on less than 10 actions (Create, Edit etc)
2) Have Input, Output Parameters
3) Provide Administrators interface / window to configure the parameters or triggers configurations.




Plugins
1) Run on 200+ Messages
2) Don't provide interface to configure parameters
3) Provide Plugin Registration tool to register and configure attributes and plugin to be ran on.



I wrote in hurry, I will update the plugin part later. If you can add for me, that will be great!!!


㉺㉼㉴㉳㉽㉾㈕㈔㈆㈅㈄㈄㈃㈁㈀㉤
Ali Hamza Wadood 
Microsoft Dynamics CRM Developer | Software Engineer - Microsoft Technologies(Asp.Net, Asp.Net MVC)
LinkedIn

Asp.Net MVC (5) - Exception Filter - HandleError

Applicable on Asp.Net MVC5 HandleError Filter This belongs to Exception Filters category (Authentication Filter, Authoriz...