Tuesday, July 25, 2023

Convert Query Expression to FetchXML

 #region Convert Query Expression to FetchXML
                var conversionRequest = new QueryExpressionToFetchXmlRequest
                {
                    Query = query
                };
                var conversionResponse = (QueryExpressionToFetchXmlResponse)this.OrgService.Execute(conversionRequest);
                var fetchXml = conversionResponse.FetchXml;

                #endregion

Sunday, July 23, 2023

Useful Links

SVG Icons

https://uxwing.com - Free SVG Icons

Edit SVG Icon Color

https://deeditor.com/

Get entity name and type code

https://YourOrgName.api.crm9.dynamics.com/api/data/v9.1/EntityDefinitions?$select=LogicalName,ObjectTypeCode 

https://www.dynamics365.is/knowledgebase/article/BLG-01019

Or from SQL Query

select Name, ObjectTypeCode from EntityView order by ObjectTypeCode

 

Jason DateTime Workflow Date Time Utilities

https://github.com/gzoug/CRM-DateTime-Workflow-Utilities 


SSL Certificates

https://letsencrypt.org

 

Experian Address Validation Configuration

https://docs.experianaperture.io/integrations/microsoft-d365-ce-pcf/get-started/form-configuration/


Using CrmSvcutil.exe

Download CrmSdkCoreTools from

https://www.nuget.org/packages/Microsoft.CrmSdk.CoreTools (See the following link for download script to run from command prompt or powershell)

https://learn.microsoft.com/en-us/power-apps/developer/data-platform/download-tools-nuget

Then, Open command prompt, navigate to tools directory and run the following command

CrmSvcUtil.exe ^
/url:[YourOrg]/XRMServices/2011/Organization.svc ^
/out:[Your]SdkTypes.cs ^
/username:[YourUsername] ^
/password:[Password] ^
/namespace:[Namespace] ^
/serviceContextName:[ContextName]

Sunday, July 9, 2023

Open SharePoint Document Location from Dynamics 365 Button using Power FX

The requirement was to open a SharePoint document location associated to a contact record in a separate tab. I was able to open the associated document location in a separate tab by using the following Power Fx code.

With({
    siteUrl: LookUp('SharePoint Sites', Name = "Default Site").'Absolute URL',
    docLocation: LookUp('Document Locations', Regarding = Self.Selected.Item)
    },
    If(IsBlank(docLocation),
        Notify($"SharePoint document location does not exist for {Self.Selected.Item.'Full Name'}."),
        With({
            url: Replace(siteUrl,1,8,"") //removes https://
            },
            With({
                domain: First(Split(url, "/")).Value //gets domain name
                },
                Launch(siteUrl & "/[YourSharePointListName]/Forms/Today.aspx?RootFolder=" & Replace(url, 1, Len(domain),"") & "/[YourSharePointListName]/" & docLocation.'Relative URL')
            )
        )
    )
)

Sunday, July 2, 2023

Create a PCF Control

Create a folder for the project. Then open the command prompt, navigate to that folder and run the following command.

pac pcf init --namespace YourNamespace --name YourComponent --template field

Install node.js from the nodejs website, then run following command in the same project directory through command prompt
 
npm install
 
Open project in Visual Studio Code by running the following command.
 
code .
 
If the above command does not work, open Folder in visual studio manually. 


Build the Package using the following command
 
npm run build

Start the package
 
npm start

Or start the package with live changes
 
npm start watch

Package PCF Component (Need visual studio build tools or visual studio full installation)
Open Developer Command Prompt for VS 2022 and run the following command
 
msbuild /t:build /restore (the restore flag is only needed the first time we are building our package)

Deploy the PCF Control
 
pac auth create --url https://[yoururl].crm[yourversion].dynamics.com

(Optional) To list authentication profiles
 
pac auth list

(Optional) To select authentication profiles
 
pac auth select --index 1

(Optional) To get profile organization details
 
pac org who
 
Push package to Dataverse
 
pac pcf push --publisher-prefix mspp
 
 
 


Wednesday, June 3, 2020

We were trying to connect Dynamics 365 instance from inside a corporate network which was having security restrictions.

It allowed outbound calls only through a proxy server. So when we tried to connect D365 using the SDK, the following error message was received.

Error Message

One or more errors occurred. => An error occurred while sending the request. => The remote name could not be resolved: 'xxx.crm4.dynamics.com'ERROR REQUESTING Token FROM THE Authentication context ERROR REQUESTING Token FROM THE Authentication contextNeed a non-empty authority Parameter name: AuthorityUnable to connect to CRM: Need a non-empty authority Parameter name: Authority Need a non-empty authority Parameter name: AuthorityUnable to Login to Dynamics CRM Unable to Login to Dynamics CRMOrganizationWebProxyClient is null OrganizationWebProxyClient is nullOrganizationWebProxyClient is null OrganizationWebProxyClient is nullOrganizationWebProxyClient is null OrganizationWebProxyClient is null

Resolution

Put the following in the config file and update the proxy address accordingly.

<system.net> <defaultProxy useDefaultCredentials="true" enabled="true"> <proxy usesystemdefault="true" proxyaddress="http://my-proxy.com:3128" /> </defaultProxy> </system.net>

For connecting to D365 using SDK, see my other blog at CrmServiceClient: Authenticate an Active Directory Account (ADFS) with CRM Online / Dynamics 365.

Saturday, April 18, 2020

CrmServiceClient: Authenticate an Active Directory Account (ADFS) with CRM Online / Dynamics 365

After going through tons of articles and experimenting with numerous console applications, I managed to establish a connection to CRM Online/Dynamics 365 environment by using an ADFS account using the following code:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var conString = @"AuthType=OAuth;Username=xxxx@domain.local; Password=xxxxxUrl=https://orgname.crm4.dynamics.com;AppId=2ad88395-b77d-4561-9441-d0e40824f9bc;RedirectUri=app://5d3e90d6-aa8e-48a8-8f2c-58b45cc67315";  
CrmServiceClient service = new CrmServiceClient(conString);  
if (service.IsReady)  
{  
    //sample request
    QueryExpression accounts = new QueryExpression("account")
    {
       ColumnSet = new ColumnSet(true)
    };  
    service.RetrieveMultiple(accounts);  
}  

The AppId and RedirectUri hard coded above are for CRM Online and do not change across the environments.

It was a local domain account which was federated with the CRM Online instance. With AuthType other than OAuth, it was redirecting to the MEX endpoint of ADFS on the local network which was failing with the following error:

"An unsecured or incorrectly secured fault was received from the other party"

Using the above approach, the CrmServiceClient class automatically handles the authentication with ADFS and we can use the normal CRUD operations of IOrganizationService.

Hope this helps!