09/08/2020

How to show a successfully submitted record's data confirmation in a canvas application

In this post let us see, how to show a successfully submitted record's data back on to the form, as a confirmation.

Take two screens 

  • Home Screen
  • Success Screen
On Home Screen:
Take a Form Control on the Home Screen and map it to respective entity. In this post we are mapping it to Registrations entity. Take a Button Control and input the below expression, to create records into Registrations Entity.

SubmitForm(frmRegistration)
Now, let us implement how to redirect the user to Success Message screen to successful record submission. In order to achieve this, we are going to make use of one of the Form Control's properties - OnSuccess. So, OnSuccess we are going to implement Success Screen navigation as below
Navigate('Success Screen')

 Success Screen

Take a label to show - success message, as below

"Registration was successful. Registration Id: " & frmRegistration.LastSubmit.'Registration Number'

LastSubmit property of a From Control helps us to show the successfully submitted record's details, including any server generated fields. So, we are leveraging this property.


06/08/2020

Redirect to a specific screen in Power Apps (Canvas App)


Here is a way to redirect to a specific screen in Power Apps (Canvas App)


The final URL looks like below https://apps.powerapps.com/play/xxxxxxxx-2c29-4c7e-b18e-a900e34c0e12?title=issueWithPhone

Get the App URL:

  1. Go to make.powerapps.com
  2. Select your canvas app. Click on three ellipses(...) and go to details
  3. copy the app URL

Add the changes in Canvas App to redirect to a specific screen or record:

  • On App Start,take a variable as below- Set(varTitle,Param("title")).
  • Use Navigate Screen to redirect to a specific screen the screen as below-If(!IsBlank(varTitle),Navigate(ViewMyRequest)).
  • We can make use of that variable to filter data and map it to form/gallery as per the requirement

02/08/2020

Convert an array to string in Power Automate (MS Flows)

converting an array value to a string using Power Automate out of the box function.

"how to convert an array to string" in MS Flows.

Basically, we can use "split" function to convert an array into string but we may end up having extra comma to the last value. To remove that we have to use another expression which checks for the string length and removes the last character [

substring(variables('varListOfRequestIDs'),0,sub(length(variables('varListOfRequestIDs')),1)) ].

To avoid this round about process rocess, we can leverage Power Automate's simple and out of the box function - join

Here is an to show how can we convert an array to string. for instance let's consider, we have an array [796759,933436,926050,1388108,762632,764554]. But as per the requirement, we need to convert it to string and send that value as 796759,933436,926050,1388108,762632,764554. 

varListOfRequestIDs = [796759,933436,926050,1388108,762632,764554]

varStringListOfRequestIDs:join(variables('varListOfRequestIDs'),',')

 gives us 796759,933436,926050,1388108,762632,764554

28/05/2019

How to add a button in D365 using Ribbon Workbench

We are going to add/create a custom button on an entity in D365 using ribbon workbench solution.

Scenario: On click of a button, we are going to generate a GUID and update that value in a field.

Prerequisites:

1. Ribbon Workbench solution (can be downloaded from the above URL)
2. Create a custom entity (in this post, we have created an entity called "Requests")
3. Create a solution and add the above entity to it
4. Create a web resource (JScript) to generate a GUID

How To?

1. Log into D365, Go to SETTINGS -> Solutions -> Click on "RIBBON WORKBENCH 2016"
2. Select a solution from the available list ("My Solution" in our post)
3. Select the BUTTON on the left side ribbon. Drag and place it on the Main Form as shown in the below image
4. Click on the + button next to COMMANDS(1) as shown below and change the Id to "new.new_request.generatekey.Command". Changing the Id value is not mandatory, its just for our convenience

a. Now click on "+ Add Action" and select "JavaScript Action"
b. Select respective Web Resource from the "Library" lookup and add the function name in "Function Name" field
Eg: Library:              $webresource:new_uniqueid.js
       Function Name: buttonGenerateKey

Click on "Add Parameter" and select "CRM Parameter". Choose "PrimaryControl" from the drop-down.



Note: This parameter helps us to get execution context on on button click

5. Now click on on the BUTTONS(1) and select the above command that we have created. Update the button labels and other fields as shown in the below image

6. Publish all the changes
7. Go to Requests entity and click on New and fill the required data. Click on "Generate Key" button. There we go, an unique key which is generated is updated in the field


Here is the sample code that's used in the post


function buttonGenerateKey(primaryControl)
{
    var formContext = primaryControl;
    var uniqueNumber = this.generateUniqueKey();
    if (uniqueNumber != null)
    {
        formContext.getAttribute("new_requestkey").setValue(uniqueNumber);
    }
    else return;
};
function generateUniqueKey()
{
    var d = new Date().getTime();
    if (Date.now)
    {
            d = Date.now();
    }
    var uniqueID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c)
    {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
    return uniqueID;
}

02/02/2019

Sample console application to connect MS CRM / D365

Here is a sample console application, to get connected with MS CRM / D365
Make sure, you are using .Net 4.6 framework. In case you are using .Net Framework below 4.6, please uncomment ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; in the below code. The main purpose of this to provide more secure connectivity to the application, in which we have Microsoft updated and industry standard security policies.

For more information on this, please refer here

Steps:

1. Open Visual Studio, click on New Project
2. Select Visual C# and chose Console Application in the right pane.
3. Chose a desired name and location to the application
4. Go to Tools -> NuGet Package Manager -> Package Manager Console
5. In the console window, paste this - Install-Package Microsoft.CrmSdk.CoreTools -Version 9.0.2.6

Earlier, we used to add all the required CRM dlls from CRM SDK, now this the above NuGet package is taking care of that and it contains official SDK tools authorized by Microsoft.

Code:


using System;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

namespace CRMConsoleApp
{
    /// <summary>
    /// Program Class
    /// </summary>
    public class Program
    {
        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            IOrganizationService organizationService = ConnectCRM();
            if (organizationService != null)
            {
                Guid currentUserGuid = ((WhoAmIResponse)organizationService.Execute(new WhoAmIRequest())).UserId;
                if (currentUserGuid != Guid.Empty)
                {
                    Console.WriteLine("User GUID: " + currentUserGuid.ToString());
                }
            }
        }
        /// <summary>
        /// Connecting to CRM
        /// </summary>
        /// <returns>IOrganization Service</returns>
        public static IOrganizationService ConnectCRM()
        {
            IOrganizationService organizationService = null;
            String username = "******@******.onmicrosoft.com";
            String password = "******";
            try
            {
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.UserName.UserName = username;
                clientCredentials.UserName.Password = password;
                //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                organizationService = (IOrganizationService) new OrganizationServiceProxy(new Uri("https://******.crm.dynamics.com/XRMServices/2011/Organization.svc"), null, clientCredentials, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught - " + ex.Message);
                Console.ReadLine();
            }
            return organizationService;
        }
    }

}

27/10/2017

Dependent Lookup in MS CRM 2016 and D365

Dependent Lookup in MS CRM 2016 and D365

Requirement: When a value selected in a lookup, related records for that lookup should be filtered in another lookup.

Eg: let’s say, we have Out Of SLA Reason and Out Of SLA Sub Reason lookup (entities). When a value is selected from Out Of SLA Reason Lookup, only related records of that value should be visible in Out Of SLA Sub Reason lookup.

Implementation:

  • Create two custom Entities – Out Of SLA Reason and Out Of SLA Sub Reason
  • Create a 1: N relationship (Referential) in Out Of SLA Reason with Out Of SLA Sub Reason. Which creates a lookup of Out Of SLA Reason in Out Of SLA Sub Reason entity.
  • Now go to Out Of SLA Sub Reason form and Out Of SLA Reason lookup on the form.



  • Now populate the data in Out Of SLA Reason and Out Of SLA Sub Reason.
  • Once data populated, go to Out Of SLA Sub Reason and select the related SLA Reason records from lookup for Out Of SLA Sub Reason records.
  • Now go to SLA Reason, SLA Sub Reason entities and create 1: N relationship (referential) to related entities.
  • Eg: If we want to show these lookup on Case. Create 1: N relationship (referential) from Out Of SLA Reason and Out of SLA Sub Reasons to Case entity. Which creates two lookup on Case entity.
  • Open case form and add these two lookup on the form.
  • Open Field Properties of Out Of SLA Sub Reason lookup from case form and go to Related Records Filtering section. Click on Only Show records where, choose Out Of SLA Reason (cases) and in contains Out of SLA Reason (Out Of SLA Sub Reason).

Now, when we click on Out Of SLA Reason and selects a record, only related records of that will show on Out Of SLA Sub Reason.


31/05/2016

We have been trying to update the blog with all the MS CRM information ....
Enjoy our MS CRM blog, please do leave feedback in the comments.