Plugin registration profile record not getting created – Dataverse / Dynamics 365


Recently while trying to debug a plugin with Persist to Entity mode on the update step, we didn’t find any profile record getting created.

One option is to try to reinstall the profiler. This could happen when we are using a different version of the plugin registration tool and it has the Profiler already installed/configured from the other version of the tool.

If that doesn’t help, then opt for Exception mode, that has always worked.

Hope it helps..

Advertisements
Advertisement

Getting started with TypeScript


TypeScript is an open-source programming language developed and maintained by Microsoft.

TypeScript adds Type support to JavaScript, which makes sure type checking is done resulting in fewer bugs, adds autocomplete supports in the TypeScript editor, supports Object Orientation and structuring and packing of the code, etc.

The code written in TypeScript transpiles to JavaScript by TSC i.e. TypeScript Compiler.

The easiest way to install TSC is to install it as a Node.js package using NPM i.e. Node Package Manager at the command line.

Download and install Node.js first if it is not already installed.

https://nodejs.org/

Make sure to include Node.js runtime and npm package manager.

Now to install TSC, open the terminal and type the below command

npm install -g typescript

g makes sure that it is installed globally and not just in the directory from which we are running the command.

There are different editors available for TypeScript

Let us see how to configure TypeScript for Visual Studio Code.

Download link for Visual Studio Code (if not already installed)

https://code.visualstudio.com/

Open Visual Studio Code and select the working folder or

in Node.js command prompt, create the directory and open the visual studio code from there

From file explorer in Visual Studio Code, create the new .ts file

Create the typescript file with the extension .ts and add the JavaScript code

To compile the TypeScript code, open the integrated Terminal in Visual Studio Code and type

tsc <<FileName.js>>


This creates a new corresponding JavaScript file for the TypeScript file.

To run it use the node command

node <<filename>>

We can also modify the TypeScript compiler’s default behavior by adding tsconfig.json.

Here we have added tsconfig.json file in the project with the following code

Check below link for different compilerOptions

https://www.typescriptlang.org/docs/handbook/compiler-options.html

To configure the build, execute Run Build Task…

As we have created the tsconfig.json file earlier, we will be presented with the following option

Select tsc: build to run the build task.

If tsc: watch is selected the compiler will watch for the changes in TypeScript files and runs the transpiler whenever the changes are saved.

To set the build or watch task as default, select Configure Default Build Task from the Terminal menu.

On selecting tsc: build task, tasks.json file is added inside .vscode

This sets build task as default, so now when we run the Run Build Task, we are not prompted to select a task.

This completes the basic environment setup for using TypeScript with Visual Studio Code.

Hope it helps..

HideCustomAction and Display \ Enable rule in Dynamics 365


Imagine a scenario where we have both the disable rule and HideCustomAction implemented for a ribbon button. Let us see with an example what will happen in this scenario.

First, let us implement the display rule to hide the Delete button from Contact form when it is in a disabled state.

For active record à

We can see the delete button in the command bar.

For disabled record à The delete button is not visible.

Now let us hide the button using HideCustomAction

Interestingly the Delete button is not available in case of the active contact record this time.

The reason for this is because the HideCustomAction button removes the specified node from the ribbon so that it is not rendered instead of hiding it. Therefore any other enable or display rules are not applied to that button.

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/customize-dev/define-custom-actions-modify-ribbon#hide-custom-actions

Hope it helps..

How to – Use Plugin on Pre-Validation Stage in Dynamics 365 CE


Recently we had a requirement to delete the Account record without deleting the associated Contact records.

If we try deleting the account record we’d get the following message box

The relationship definition can’t be updated as well to achieve this

So, we wrote a plugin on the pre-validation stage of pre-delete event of Account, which will retrieve and loop through all the child contact records and set its parent customer field as null.

In case of pre-operation the child records were not available.

</p>
<p>public void Execute(IServiceProvider serviceProvider)<br />
{<br />
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));<br />
IPluginExecutionContext pluginContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));<br />
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));<br />
IOrganizationService organizationService = serviceFactory.CreateOrganizationService(pluginContext.UserId);<br />
EntityReference targetEntity = (EntityReference)pluginContext.InputParameters["Target"];<br />
QueryExpression getContacts = new QueryExpression("contact");<br />
getContacts.Criteria.AddCondition(new ConditionExpression("parentcustomerid", ConditionOperator.Equal, targetEntity.Id));EntityCollection allContacts = organizationService.RetrieveMultiple(getContacts);foreach (Entity contact in allContacts.Entities)<br />
{<br />
Entity contactToBeUpdated = new Entity("contact");<br />
contactToBeUpdated.Id = contact.Id;<br />
contactToBeUpdated.Attributes["parentcustomerid"] = null;<br />
organizationService.Update(contactToBeUpdated);<br />
}}<br />

Another practical scenario

https://www.inogic.com/blog/2017/03/plugin-pre-validation-operation-to-show-an-error-message-as-well-as-log-the-error/

Hope it helps..

Advertisements

Plugin on AddListMembers message. When does it fire?


In one of our recent implementations involving marketing list entity, we were analysing the AddListMembers message for it.

We registered a plugin on AddListMembers message and below were our findings.

  • Dynamics Marketing List – The plugin didn’t trigger.
  • Static Marketing List – The plugin didn’t trigger for “Add using Lookup“. It only triggered for “Add using Advanced Find” when “Add only the selected members to the marketing list” option was selected. It didn’t trigger for “Add all the members returned by the search to the marketing list

 

This slideshow requires JavaScript.

So basically, we need to be very careful while implementing a plugin on AddListMembers message.

Hope it helps..

Using MediaWiki API for Showing content of Wikipedia page inside Dynamics 365 form


Hi,

Recently we had a requirement to show content of Wikipedia page and display it inside CRM in one of the entities form.

For this purpose, we can make use of “MediaWiki web service API.”

https://www.mediawiki.org/wiki/API:Main_page

To create the query, we can use the below tool

https://en.wikipedia.org/wiki/Special%3aApiSandbox

The html source code


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">

function SetWikiContent() {

// get country name from crm form
if (Xrm.Page.getAttribute("new_name") != null) {

var title = Xrm.Page.getAttribute("new_name").getValue();

// set the url
var url = "https://en.wikipedia.org/w/api.php?format=json&action=parse&page=" + title + "&prop=text&section=0&callback=?";

$.getJSON(url, function (data) {
for (text in data.parse.text) {
var text = data.parse.text[text].split("
");
var pText = "";

for (p in text) {
//Remove html comment
text[p] = text[p].split("<!--");
if (text[p].length > 1) {
text[p][0] = text[p][0].split(/\r\n|\r|\n/);
text[p][0] = text[p][0][0];
text[p][0] += "
 ";
}
text[p] = text[p][0];

//Construct a string from paragraphs
if (text[p].indexOf("
") == text[p].length - 5) {
var htmlStrip = text[p].replace(/<(?:.|\n)*?>/gm, '') //Remove HTML
var splitNewline = htmlStrip.split(/\r\n|\r|\n/); //Split on newlines
for (newline in splitNewline) {
if (splitNewline[newline].substring(0, 11) != "Cite error:") {
pText += splitNewline[newline];
pText += "\n";
}
}
}
}
pText = pText.substring(0, pText.length - 2); //Remove extra newline
pText = pText.replace(/\[\d+\]/g, ""); //Remove reference tags (e.x. [1], [4], etc)

Xrm.Page.getAttribute('new_wikiinfo').setValue(pText);
}
});
}
}

</script>
</head>
<body onload="SetWikiContent();">
</body>
</html>

The helpful article

http://stackoverflow.com/questions/8555320/is-there-a-clean-wikipedia-api-just-for-retrieve-content-summary

Hope it helps..

%d bloggers like this: