CRM, Microsoft CRM Dynamics, Microsoft Dynamics CRM

How to resolve access issues in D365

Many times you would bump into Users having issues with creating/updating records in D365 due to some permission issue and the system would generate a similar looking error message:

Error message

The error message is not explanatory so that one can figure out the entity for which the permission is missing. What we need to do here is to search for the  ObjectTypeCode online (In my case it’s 1141). Once we do a search and know the corresponding entity, we need to give necessary permissions for User’s security role (In my case I had to give Append and AppendTo permission). Once I gave the permissions, the User was able to create the record.

 

 

Advertisements
Standard
CRM, Microsoft CRM Dynamics, Microsoft Dynamics CRM

Custom Filter on lookup Dynamics 365

The usual method to go about creating a filtered lookup is using FetchXML condition and add “addPreSearch()” method on the field where the filter is required.

The obvious challenge with this approach is maintainability as there’s javascript involved.

In D365 you can now configure filters on a lookup in the following manner:

Go to field properties for the field you want to be filtered and under Related Records Filtering, check Only show records where. Select the filter condition and you are done 🙂

Filtered lookup D365

Standard
C#, CRM, Microsoft CRM Dynamics, Microsoft Dynamics CRM

TCP/IP based Integrations in CRM Dynamics On Prem

We recently had a requirement to Integrate with a System using MML(Man Machine Language) Commands with CRM Dynamics.

Sending MML commands to systems is done using TCP/IP protocol. Let’s first see the Sequence Diagram for the Integration:

sequencediagram

 

Here is the Source code for a Sample Console App we used for a POC, same code can be used from a Windows service or a Desktop application if required with few tweeks:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace EMATestingConsoleApp
{
    class Program
    {
        // Receiving byte array  
        static byte[] bytes = new byte[1024];
        static Socket senderSock;

        static void Main(string[] args)
        {
            Console.WriteLine("Connect to server? Press any key to continue connecting..");
            Console.ReadKey();

            try
            {
                // Create one SocketPermission for socket access restrictions 
                SocketPermission permission = new SocketPermission(
                    NetworkAccess.Connect,    // Connection permission 
                    TransportType.Tcp,        // Defines transport types 
                    "",                       // Gets the IP addresses 
                    SocketPermission.AllPorts // All ports 
                    );

                // Ensures the code to have permission to access a Socket 
                permission.Demand();

                var ipAddr = IPAddress.Parse(System.Configuration.ConfigurationManager.AppSettings["ipaddress"]);
                var port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["port"]);
                // Creates a network endpoint 
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, port);

                // Create one Socket object to setup Tcp connection 
                senderSock = new Socket(
                    ipAddr.AddressFamily,// Specifies the addressing scheme 
                    SocketType.Stream,   // The type of socket  
                    ProtocolType.Tcp     // Specifies the protocols  
                    );

                senderSock.NoDelay = false;   // Using the Nagle algorithm 

                // Establishes a connection to a remote host 
                senderSock.Connect(ipEndPoint);
                Console.WriteLine("Socket connected to " + senderSock.RemoteEndPoint.ToString());

                Console.WriteLine("Enter command to be sent to EMA");
                

                try
                {
                    // Sending message 
                    //<Client Quit> is the sign for end of data 
                    string theMessageToSend = Console.ReadLine();
                    byte[] msg = Encoding.Unicode.GetBytes(theMessageToSend + "<Client Quit>");

                    // Sends data to a connected Socket. 
                    int bytesSend = senderSock.Send(msg);

                    ReceiveDataFromServer();

                
                }
                catch (Exception exc) { Console.WriteLine(exc.ToString()); }

                Console.ReadLine();
            }
            catch (Exception exc) { Console.WriteLine(exc.ToString()); }

        }

        private static void ReceiveDataFromServer()
        {
            try
            {
                // Receives data from a bound Socket. 
                int bytesRec = senderSock.Receive(bytes);

                // Converts byte array to string 
                String theMessageToReceive = Encoding.Unicode.GetString(bytes, 0, bytesRec);

                // Continues to read the data till data isn't available 
                while (senderSock.Available > 0)
                {
                    bytesRec = senderSock.Receive(bytes);
                    theMessageToReceive += Encoding.Unicode.GetString(bytes, 0, bytesRec);
                }

                Console.WriteLine("The server reply: " + theMessageToReceive);
                Console.WriteLine("Press any key to disconnect");
                Console.ReadKey();

                // Disables sends and receives on a Socket. 
                senderSock.Shutdown(SocketShutdown.Both);

                //Closes the Socket connection and releases all resources 
                senderSock.Close();
            }
            catch (Exception exc) { Console.WriteLine(exc.ToString()); }
        }

      

    }
}

 

 

 

Standard
C#, CRM, Microsoft CRM Dynamics

String.Equals returning false even for same strings

If you are startled by seeing String.Equals returning false for exactly similar looking strings, this is what you need to do:

  1. Check if both strings have equal lengths, if not return
  2. Check Trimmed versions of both strings, there maybe extra white-spaces that get unnoticed.
  3. Finally if both lengths are equal and trimmed versions look exactly the same, the issue could be the encoding of the spaces in the 2 strings as they maybe be coming from different sources. In this case, use the following code to correct the encoding:

image 

Using regex, I have just replaced the unicode equivalent of space with a space.

Standard