Important points to note for the intellisense of calculated fields

Consider below scenario to understand calculated field intelligence logic.

1. I have created custom field called lookup and relate to system entity called ‘Unit’ with named ‘new_uomid’.

2.  Created new custom field as string (Calculated) and tried to set action (Calculated field) with lookup value as ‘new_uomid’.  I have added dot after ‘new_uomid’ field to get intellisense but it did not appears.

3. Then , I have created new custom field called lookup and relate to system entity called ‘Account’ with named ‘new_accountid’

4. Open existing string field and tried to set action (Calculated field) with lookup value ‘new_accountid’, then I have added dot to get intelligence and it is working properly.

Reason : Each entity have metadata property called ‘IsValidForAdvancedFind’. If this properly is true then only you will get intellisense option in calculated field for selected entity. In simple words if entity is visible in advanced filed view  then you will get intellisense option in calculated field.

Sample plugin to create record when other entity record was created

The below example shows how to create an Contact record whenever we had an account record getting created.

Find the code as below.

Step 1:


using System;
using Microsoft.Xrm.Sdk;// include this dll from SDK
namespace plugin_721
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider service1)
{
IPluginExecutionContext context = (IPluginExecutionContext)service1.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
entity.LogicalName = "account";
try
{
Entity createcontact = new Entity("contact");
if (context.PrimaryEntityId != null)
{
createcontact["firstname"] = "pavan";
}
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)service1.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
service.Create(createcontact);
}
catch (Exception ex)
{
//code you for displaying when exception was caught, not compulsory
}
}
}
}
}

view raw

Plugin.cs

hosted with ❤ by GitHub

Step 2: 

Dont forget to sign in the assembly.

Build the code in the visual studio to get the dll file.

Step 3:

Open Plugin registration tool from  crm 2016 SDK\SDK\Tools\PluginRegistration

  1. create a new connection
  2. give the organization login details select O365 if online
  3. Select your region
  4. Displays the organizations if found
  5. Click Register–>Register new Assembly–>Select your DLL
  6. Select sandbox & Database if online–> Register
  7. Goto the Assembly and create a new step for that
  8. Select the details asked, can select required pipeline execution order, stage, execution mode, deployment
  9. Enter register step
  10. Your plugin was registered
  11. Go and check, when you had created a new account, this code would create a contact pavan(You can give whatever you want).

Cheers,

PMDY