Sunday 5 July 2020

Consume Microsoft Dynamics NAV/BC ODATA using .NET C#

I meddled into consuming NAV Odata using C# this evening.

The walkthrough followed as documented by Microsoft: Walkthrough: Creating and Interacting with a Page Web Service (OData)

I had made some changes as my request is quite different and below is what I did:

Tools Used

  1. VS 2017
  2. OData Connected Service.
    1. Download from here: OData Connected Service OR
    2. Download from VS => Tools => Extension and Updates => Search for OData Connected Service.
Steps
  • Expose the Odata URL/endpoint on NAV/BC
  • Get Authorization Code: I used Postman to get this.

  • Create Console Application on VS2017
  • Add Connected Service to the project
  • Enter Service Name, Address, Authorization header


  • Use the necessary references and namespace of the service

  • See code sample

using System;using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using NAV;
namespace NAVConsole
{
class Program
{
static void Main(string[] args)
{
String username = "Test";
String password = "your password";
NAV.NAV nav = new NAV.NAV(new Uri("http://<servercomputer>:<odataport>/<serverinstance>/ODataV4/Company('PILOT')"));
nav.Credentials = new NetworkCredential(username, password);
PrintSalaryAdvances(nav);
Console.ReadLine();
}
private static void PrintSalaryAdvances(NAV.NAV nav)
{
var salAdv = from s in nav.StockAutomationCard
select s;
foreach (var item in salAdv.ToList())
{
Console.WriteLine($"Requester: {item.User_ID}, No: {item.No}");
}
}
}
}


  • Result


Saturday 4 July 2020

Start workflow from button in Microsoft Dynamics CE.

Executing workflow from the ribbon button in the days of the Classic Interface of Dynamics CRM/CE requires a mix of the JavaScript and workflow.

But with the advent of Smart Buttons by Scott Durrow, things are a lot easier and compatible with Dynamic CE unified interface.

Here is the link that explains the features and usage:  Smart Buttons for Unified Interface
Here is the link to download and install the SmartButton solution: SmartButtons Solution

Enjoy ✌

Wednesday 1 July 2020

Show/Hide button based on security role using Entity Privilege on Microsoft Dynamics CE

I came across this request sometimes ago but I implemented it using code: JavaScript. Nevertheless, my client still experienced issues because the button is not visible at certain times.

So I had to search for another solution: using Entity Privilege. This is simple and it works well.

The steps are below. These steps are grouped into two

  1. On the Ribbon WorkBench Tool (RWB Tool)
  2. On Dynamics 365/CRM: Entity and Security Customization
My scenario is to show Procure button on quote entity when quote status is Won for a user with Procurement Officer or Procurement Admin Role

On Dynamics: Entity and Solution Creation

  • Create an entity. e.g. button access
  • Add the new entity (button access) and other entities you want to work on in the RB Tool to a solution

On RWB Tool

  • Open Ribbon Work Bench tool (RB Tool) and select your solution
  • Right-click the button and choose "customize command"

  • Display Rule: Add an EntityPrivilegeRule, 
    • Set Default to True
    • EntityName to the new entity created (button access)
    • PrivilegeDepth to Basic
    • PrivilegeType to Create or anyone you wish

  • Add Display Rule to Command

  • Publish your ribbon customization.

On Dynamics: Security 

  • Open Security role and select anyone you want to edit
  • Select Custom entities and locate the new entity (button access)
  • Give User/Basic Privilege as shown in the image below
  • Procure Button on Quote entity.


Entity mapping for fields in Microsoft Dynamics CE

Customizing entities is a norm when you extend in Dynamics CRM. I came across entity mapping twice so I decided to blog this as a reference to me and any other finding solution.

It quite easy to map attributes in entities with visible relationships in Dynamics CRM but for hidden relationships, you have to go through some steps to map these custom fields/attributes

Prerequisites before mapping:

Ensure there is an existing relationship between the entities and get the Mapping ID: You can confirm through

Get EntityMap Id

  • Get All Entity Maps: This displays a list of all mapping existing in your environment. 
[Organization URI]/api/data/v9.0/entitymaps?$select=sourceentityname,
targetentityname&$orderby=sourceentityname
Example
{"@odata.etag":"W/\"1145417\"","sourceentityname":"account", 
"targetentityname":"customeropportunityrole", 
"entitymapid":"57efb32f-b9ec-e911-a812-000d3a25c8cc"}, 

OR

  • Get a Specific Entity Map: Between SalesOrderDetail and InvoiceDetail
[Organization URI]/XRMServices/2011/OrganizationData.svc/EntityMapSet?$
select=EntityMapId&$filter=SourceEntityName eq "salesorderdetail" and
TargetEntityName eq "invoicedetail"
The EntityMapId will be the same

Create Mapping

Use the entitymapid
[Organization URI]/Tools/SystemCustomization/Relationships/Mappings/
mappingList.aspx?mappingId=57efb32f-b9ec-e911-a812-000d3a25c8cc