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



















































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

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