I want to call plugin using java script
this function send entityrefernce only
function CallAction() {
var currentRecordIdString = Xrm.Page.data.entity.getId();
var currentRecordId = currentRecordIdString.replace("{", '').replace("}", '');
Process.callAction("new_Trigger",
[{
key: "Target",
type: Process.Type.EntityReference,
value: new Process.EntityReference("contact", Xrm.Page.data.entity.getId())
}],
function (params) {
// Success
alert("success");
},
function (e, t) {
// Error
alert("error");
});
}
Plugin code is given exception than entityreference can't convert to entity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
namespace testplugin
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName == "contact")
{
if (entity.Attributes.Contains("jobtitle") == false)
{
entity.Attributes.Add("jobtitle", "MPS");
}
else
{
throw new InvalidPluginExecutionException("The description can only be set by the system.");
}
}
}
}
}
}
*This post is locked for comments