用于更新MSCRM中的值的JavaScript [英] JavaScript to update values in MSCRM
问题描述
我正在研究CRM
我想用约会实体中的值更新联系人实体。
联系人实体有两个字段最后约会日期和下一个约会日期。
约会实体中的两个字段,称为开始日期和结束日期。应将这两个值复制到联系人字段值。
我希望使用JavaScript实现这一点
I am working on CRM I want to update the contact entity with values in the appointment entity. Contact entity has two fields Last Appointment Date and Next Appointment Date. two fields in Appointment entity called Start Date and End Date. These two value should be copied to contact field values. I want this to happen using JavaScript
推荐答案
如果它是一个插件对我来说也没问题..实际上首先我尝试插件。我没有通过它。所以我转向java脚本。
这是我使用的代码。
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
If it's a plug-in too no problem for me.. actually first i tried in plug-in. I did not get through it. So i moved to java script. This is the code which i used. public void Execute(IPluginExecutionContext context) { DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (entity.Name != EntityName.appointment.ToString())
return;
}
else
{
return;
}
try
{
Guid appointmentID = new Guid(context.OutputParameters["id"].ToString());
ICrmService crmservice = context.CreateCrmService(true);
appointment appObj = (appointment)crmservice.Retrieve(EntityName.appointment.ToString(), appointmentID, new ColumnSet(new string[] { "regardingobjectid", "location" }));
if (appObj.regardingobjectid == null || appObj.regardingobjectid.type != "contact")
{
return;
}
Guid contactID = appObj.regardingobjectid.Value;
contact cnt = new contact();
cnt.contactid = new Key();
cnt.contactid.Value = contactID;
cnt.firstname = appObj.location;
crmservice.Update(cnt);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
"Invalid plug-in.", ex);
}
}
这篇关于用于更新MSCRM中的值的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!