Thursday, November 24, 2022

Lookup view change in related records

 Requirement:

Instead of Name, need to add application number here (as shown below)

Steps to Achieve:

1. Go to the Look up view in the Views.

2. Then click on add columns.

3. Then Save and Publish the changes


Output:

Open CRM Form Lookup value you can get Application Number.

 




















Wednesday, November 9, 2022

Check box configuration on MS CRM (Dynamics 365 CRM) Forms.

  Requirement:

Check box configuration on MS CRM forms (as shown below)





Steps to Achieve:

1. Create new field with Two option Data type.

2. Add field into the form, then click on the change property

3. Then go to the Formatting tab in Fild property.

4. Finally go to Control Formatting option, here choose the Check Box option.

(Note: Save and publish your changes)

Output:


Open CRM Form you can get the check box of that field.







.






















Tuesday, November 8, 2022

Autonumber Configuration in Power Apps

 Requirement:

Customer Require every application/records has it own unique number with below format.

Format: ABCBK  - Year – Month -Date-RandomNumber

Sample number - ABC – 2022-06-06-001

Steps to Achieve:

Go to the https://make.powerapps.com/

Configuration of AutoNumber in Power Apps

1. Choose you required Tables from the list

2. Choose the list of columns 

3. In the top left, create a New Column by clicking on the + New column

4. Give meaningful name to Field

5. Choose the Date Type by clinking on down arrow mark

6. Choose Autonumber Data Type

7. Choose Autonumber Type - (String prefixed number, Date prefixed number and Custom)

      for now I have select Custom.

8. Choose your required Formats, by choosing the Append option

9. In Append we have a multiple options - (Add sequential number to format, Add datetime to format  and Add random string to format)

for now I have selected Add datetime to format option and I have added String before the datetime

10. Then check your final preview of the autonumber


Finally, you have to save app changes and publish your changes, then only changes will commit.



Output
Create a New form Dynamics 365 CRM, then you can see the Application Number.














(Note: This Autonumber will generate when your trying to creating a new record and after saving the record you can get application number)




























Monday, November 7, 2022

File DataType configuration in MS CRM (Power Apps)

Requirement:

Customers require upload files from local machine in Dynamics 365 CRM application form.

Steps to Achieve:

Go to the https://make.powerapps.com/

1. Choose you required Tables from the list

2. Choose the list of columns 

3. In the top left, create a New Column by clicking on the + New column










4. select the data type by click the Date Type option

5. then select File

6. You will get two options, file and Image, choose the File option










7. choose the Filed Required level

8. Save the Filed











10. Then place the field on the form

Finally, you have to save app changes and publish your changes, then only changes will commit.

Output: 
Open the respective form in Dynamics 365 CRM, you can see the Choose File option to upload the files











Monday, August 1, 2022

Create complex dynamic views in Dynamics 365 CRM

Views in Dynamics are based on the filter.Via a filter a query is in fact defined. However, the possibilities are limited when defining a filter. In this blog I will explain an approach with which it is possible to create more complex view filters. This approach uses a pre-operation RetrieveMultiple plugin, which modifies the view filter query before it is executed in Dynamics. In this way much more complex views can be created than is normally possible.

The case

In this example, we will create a dynamic view, which allows you to see a list of records from the based on logged in user State along with TPA and investor values.




below 2 values I'm trying to set dynamic values.

The approach

As said a view in Dynamics is nothing else than a query. When you, as a Dynamics user, use a view to look at certain records, a RetrieveMultiple call takes place in Dynamics where the filter query is given, executed and the found records are returned and shown.

The way we are going to make the view logic dynamic consists of the following steps:

Defining the view filter, containing a certain specific condition
Building a RetrieveMultiple plugin, which recognizes the view filter from step 1 and adapts it
Adding the plugin step, so the plugin will be used


Step 1: Definition of the view filter
In this step, we define the view filter (as System View, so it is available to all users). We include a dummy condition [Name Equals CallReportsOfInterestToCurrentUser] to make the filter query recognizable to our plugin to be built.


Step 2: building the plugin
In this step, we first create the plugin code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
using System.Web;

namespace FilterQuoteView
{
    public class FilterQuoteView : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {

            ITracingService Tracingservice = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            try
            {

                if (context.MessageName == "RetrieveMultiple" && context.InputParameters.Contains("Query") && context.Depth < 2)
                    if (context.InputParameters["Query"] is FetchExpression)
                    {
                        var thisQuery = context.InputParameters["Query"];
                        var fetchExpressionQuery = thisQuery as FetchExpression;
                        var query = fetchExpressionQuery.Query;
                        if (fetchExpressionQuery != null)
                        {
                                //QueryExpression query = (QueryExpression)context.InputParameters["Query"];

                                string queryString = query.ToString();
                                Tracingservice.Trace("Query Value : {0}", queryString);
                                if (!(queryString.Contains("abc_tpacommissionamount")))
                                {
                                    Tracingservice.Trace("Selected non TPA/Investor commission View");
                                    return;
                                }
                                Guid user = context.UserId;
                                Tracingservice.Trace("User :" + user);

                                string userquote = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                      <entity name='quote'>
                                        <attribute name='quoteid' />
                                        <attribute name='createdon' />
                                        <attribute name='abc_customer' />
                                        <attribute name='quotenumber' />
                                        <attribute name='ownerid' />
                                        <order attribute='createdon' descending='true' />
                                        <filter type='and'>
                                          <condition attribute='abc_overallstatus' operator='eq' value='799240001' />
                                          <condition attribute='ownerid' operator='eq' uitype='systemuser' value='" + user + @"' />
                                        </filter>
                                        <link-entity name='abc_address' from='abc_addressid' to='abc_address' visible='false' link-type='outer' alias='ab'>
                                          <attribute name='abc_state' />
                                          <attribute name='abc_district' />
                                          <attribute name='abc_city' />
                                        </link-entity>
                                      </entity>
                                    </fetch>";

                                EntityCollection QuoteDetails = service.RetrieveMultiple(new FetchExpression(userquote));
                                Tracingservice.Trace("Quote :" + QuoteDetails.Entities.Count);
                                
                                if (QuoteDetails.Entities.Count > 0)
                                {
                                    Tracingservice.Trace("User has Quotes for TPA/Investor Approval");

                                    string Mapping = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                              <entity name='abc_usergeographicalmapping'>
                                                <attribute name='abc_usergeographicalmappingid' />
                                                <attribute name='abc_name' />
                                                   <attribute name='abc_state' />
                                                <attribute name='createdon' />
                                                <order attribute='abc_name' descending='false' />
                                                <filter type='and'>
                                                  <condition attribute='abc_employee' operator='eq' uitype='systemuser' value='" + user + @"' />
                                                </filter>
                                              </entity>
                                            </fetch>";
                                    EntityCollection userMapping = service.RetrieveMultiple(new FetchExpression(Mapping));


                                    Tracingservice.Trace("User States :" + userMapping.Entities.Count);

                                    List<Guid> stateId = new List<Guid>();


                                    if (userMapping.Entities.Count > 0)
                                    {
                                        Tracingservice.Trace("User has States Assigned");
                                        //Guid[] guids = new Guid[] { };

                                        foreach (Entity userGraphicalMapping in userMapping.Entities)
                                        {
                                            //guids = userMapping.Entities.Select(con => userGraphicalMapping.GetAttributeValue<EntityReference>("abc_state").Id).ToArray();

                                            stateId.Add(userGraphicalMapping.GetAttributeValue<EntityReference>("abc_state").Id);

                                        }
                                        String State = "";
                                        for (var i = 0; i < stateId.Count; i++)
                                        {   // Assuming that you have array of Guid which is GuidArray .
                                            State += "<value>" + stateId[i] + "</value>";
                                        }
                                        Tracingservice.Trace("Query Value : {0}", State);

                                        string TPAratedetails = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                              <entity name='abc_benchmarkrate'>
                                                                <attribute name='abc_benchmarkrateid' />
                                                                <attribute name='abc_type' />
                                                                <attribute name='abc_state' />
                                                                <attribute name='abc_rate' />
                                                                <attribute name='abc_clienttype' />
                                                                <order attribute='abc_clienttype' descending='false' />
                                                                <filter type='and'>
                                                                  <condition attribute='abc_state' operator='eq' value='" + stateId[0] + @"' />
                                                                  <condition attribute='abc_type' operator='eq' value='2' />
                                                                  <condition attribute='abc_clienttype' operator='eq' value='{7667B824-0A15-EB11-A813-000D3AF0247A}' />
                                                                </filter>
                                                              </entity>
                                                            </fetch>";
                                         EntityCollection TPADetails = service.RetrieveMultiple(new FetchExpression(TPAratedetails));
                                        List<Money> tpa = new List<Money>();

                                        foreach (Entity abc_benchmarkrate in TPADetails.Entities)
                                        {
                                            //guids = userMapping.Entities.Select(con => userGraphicalMapping.GetAttributeValue<EntityReference>("abc_state").Id).ToArray();

                                            tpa.Add(abc_benchmarkrate.GetAttributeValue<Money>("abc_rate"));
                                            

                                        }
                                        Money TPArate = tpa[0];
                                        Tracingservice.Trace("TPA Rates :" + tpa[0].Value.ToString());

                                         string Investorratedetails = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                                              <entity name='abc_benchmarkrate'>
                                                                <attribute name='abc_benchmarkrateid' />
                                                                <attribute name='abc_type' />
                                                                <attribute name='abc_state' />
                                                                <attribute name='abc_rate' />
                                                                <attribute name='abc_clienttype' />
                                                                <order attribute='abc_clienttype' descending='false' />
                                                                <filter type='and'>
                                                                  <condition attribute='abc_state' operator='eq' value='" + stateId[0] + @"' />
                                                                  <condition attribute='abc_type' operator='eq' value='1' />
                                                                  <condition attribute='abc_clienttype' operator='eq' value='{7667B824-0A15-EB11-A813-000D3AF0247A}' />
                                                                </filter>
                                                              </entity>
                                                            </fetch>";
                                         EntityCollection InvestorDetails = service.RetrieveMultiple(new FetchExpression(Investorratedetails));

                                        List<Money> invstrrate = new List<Money>();

                                        foreach (Entity abc_benchmarkrate in InvestorDetails.Entities)
                                        {
                                            //guids = userMapping.Entities.Select(con => userGraphicalMapping.GetAttributeValue<EntityReference>("abc_state").Id).ToArray();

                                            invstrrate.Add(abc_benchmarkrate.GetAttributeValue<Money>("abc_rate"));


                                        }
                                        Money InvestorRate = invstrrate[0];
                                        Tracingservice.Trace("Investor Rates :" + invstrrate[0].Value.ToString());

                                        int pageNumber = 1;
                                        // Specify the current paging cookie. For retrieving the first page, 
                                        // pagingCookie should be null.
                                        string pagingCookie = null;

                                        string Quotefilter = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='false'>
                                                            <entity name='quote'>
                                                            <attribute name='name'/>
                                                            <attribute name='abc_customer'/>
                                                            <attribute name='createdon'/>
                                                            <attribute name='abc_product'/>
                                                            <attribute name='abc_ordervalidity'/>
                                                            <attribute name='abc_remainingquantity'/>
                                                            <attribute name='quotenumber'/>
                                                            <attribute name='abc_quantity'/>
                                                            <attribute name='abc_cancelledquantity'/>
                                                            <attribute name='abc_orderdate'/>
                                                            <attribute name='abc_warehouse'/>
                                                            <attribute name='abc_approvalstatus'/>
                                                            <attribute name='ownerid'/>
                                                            <attribute name='abc_deliveryrequiredfrom'/>
                                                            <attribute name='abc_dealncrpermt'/>
                                                            <attribute name='abc_additionalexpense'/>
                                                            <order attribute='createdon' descending='true'/>
                                                            <filter type='and'>
                                                            <condition attribute='ownerid' operator='eq' uitype='systemuser' value='" + user + @"'/>
                                                            <condition attribute='abc_overallstatus' operator='eq' value='799240001'/>
                                                            <filter type='or'>
                                                            <condition attribute='abc_tpacommissionamount' operator='gt' value='" + TPArate.Value + @"'/>
                                                            <condition attribute='abc_investorcommissionamount' operator='gt' value='" + InvestorRate.Value + @"'/>
                                                            </filter>
                                                            </filter>
                                                            <link-entity name='msdyn_warehouse' from='msdyn_warehouseid' to='abc_warehouse' visible='false' link-type='outer' alias='a_dc89ff502000ec1194ef000d3af0435a'>
                                                            <attribute name='msdyn_description'/>
                                                            </link-entity>
                                                            <link-entity name='abc_address' from='abc_addressid' to='abc_address' visible='false' link-type='outer' alias='a_ff3ebc91c000ec1194ef000d3af0435a'>
                                                            <attribute name='abc_state'/>
                                                            <attribute name='abc_district'/>
                                                            <attribute name='abc_city'/>
                                                            </link-entity>
                                                            <link-entity name='account' from='accountid' to='abc_customer' visible='false' link-type='outer' alias='a_1e7e13870900ec1194ef000d3af0435a'>
                                                            <attribute name='abc_customerclassification'/>
                                                            <attribute name='abc_customeridfinance'/>
                                                            </link-entity>
                                                            <attribute name='abc_tpacommissionamount'/>
                                                            <attribute name='quoteid'/>
                                                            </entity>
                                                            </fetch>";
                                        Quotefilter = string.Format(Quotefilter, pageNumber, pagingCookie);
                                        Tracingservice.Trace("Retreived the Quote Details");
                                        var conversionRequest = new FetchXmlToQueryExpressionRequest
                                        {
                                            FetchXml = Quotefilter
                                        };
                                        var conversionResponse = (FetchXmlToQueryExpressionResponse)service.Execute(conversionRequest);

                                        // Use the newly converted query expression to make a retrieve multiple
                                        // request to Microsoft Dynamics CRM.
                                        QueryExpression queryExpression = conversionResponse.Query;


                                        context.InputParameters["Query"] = queryExpression;
                                        Tracingservice.Trace("Passed to input Context");

                                }
                                }
                        }
                    }
                    else
                    {
                        Tracingservice.Trace("Context Value : {0}", context.InputParameters["Query"]);
                    }
            }

            catch (Exception e)
            {
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
    }
}


Step 3: adding the plugin step

Finally, we need to add a plugin step for the message retrieveMultiple, on the quote entity


Output:

our view created in step 1 is now dynamically modified by plugin code and expanded with TPA and Investor values based on the logged in user state.








Thursday, July 28, 2022

Regarding (Advanced Lookup) Tables filtering in MSCRM

Scenario: Need to filter the Regarding (Advanced Lookup) Tables.

Step 1. Check Lookup schema name




Step 2. Check loaded tables in Lookup


Step 3. Click on Advanced Lookup 

Step 4. You can find list of Tables

Step 5. I want to show only 'account','contact','lead','msdyn_warehouse','msdyn_vendor','incident' in the Table list.

Step 6. I have written JS

function setCustomFilter(context)
    {
        debugger;
        var formContext = context.getFormContext();
        var lookup = formContext.getControl("regardingobjectid");
 
        //check if multiple type dropdowns enabled for this lookup
        if (lookup.getEntityTypes().length > 1) {
            lookup.setEntityTypes(['account','contact','lead','msdyn_warehouse','msdyn_vendor','incident']);            
        }
    }

Step 7. Triggering above function on form load.

Output:

On form load, It will load only 6 entity (table)s records.


here you can find the list of tables.




*** Thank you