The Notes relationship is a 1:N relationship. By default you can associate a minimum of Zero notes.
To apply Javascript validation you will require to a valid lookup field. As you cannot create field for a note then you can use a plugin to enforce this validation.
The plugin logic:
var pluginContext = localContext.PluginExecutionContext;
if (!pluginContext.InputParameters.Contains("Target") ||
!(pluginContext.InputParameters["Target"] is Entity)) return;
var target = pluginContext["Target"] as Entity;
var annotationQuery = new QueryExpression
{
EntityName = "annotation",
ColumnSet = new ColumnSet(true),
Criteria =
{
Conditions =
{
new ConditionExpression("objectid", ConditionOperator.Equal, target.Id)
}
}
};
var response = localContext.OrganizationService.RetrieveMultiple(annotationQuery);
if (!response.Entities.Any())
throw new InvalidPluginExecutionException("No Notes were found for the entity");
//Further checks against content...
When the exception is thrown this interrupts the operation if the message for the plugin is Pre-Validation
or Pre-Operation
and the user will have to associate a note to the entity