如何通过 C# 插件使用查找 CRM 365 插入数据
How to Insert data using lookup CRM 365 through Plugin C#
我在我的实体“new_trialxrmservicetoolkit”中查找“new_lookuptransactionheader”。此查找链接自“new_transactionheader”实体。如何使用 c# crm 插件插入数据?
这个我的代码:
public void InsertDataUsingLookup(XrmServiceContext xrm, Entity entitiy, ITracingService tracer)
{
new_trialxrmservicetoolkit trial = new new_trialxrmservicetoolkit();
trial.new_name = "testplugin";
trial.new_LookupTransactionHeader = null; //this is i don't know how to get value from new_LookupTransactionHeader
trial.new_Notes = "this is test plugin using c#";
xrm.AddObject(trial);
xrm.SaveChanges();
}
我更新了我的代码并解决了这个问题:
public void InsertDataUsingLookup(XrmServiceContext xrm, Entity entitiy, ITracingService tracer)
{
new_trialxrmservicetoolkit trial = new new_trialxrmservicetoolkit();
trial.new_name = "testplugin";
trial.new_LookupTransactionHeader = new EntityReference("new_transactionheader", Guid.Parse("5564B5F0-0292-E711-8122-E3FE48DB937B"));
trial.new_Notes = "this is test plugin using c#";
xrm.AddObject(trial);
xrm.SaveChanges();
}
trial.Attributes["new_LookupTransactionHeader"] = new EntityReference("new_transactionheader", new_transactionheaderId-GUID);
您必须像上面那样使用 EntityReference
来设置查找属性。
我在我的实体“new_trialxrmservicetoolkit”中查找“new_lookuptransactionheader”。此查找链接自“new_transactionheader”实体。如何使用 c# crm 插件插入数据? 这个我的代码:
public void InsertDataUsingLookup(XrmServiceContext xrm, Entity entitiy, ITracingService tracer)
{
new_trialxrmservicetoolkit trial = new new_trialxrmservicetoolkit();
trial.new_name = "testplugin";
trial.new_LookupTransactionHeader = null; //this is i don't know how to get value from new_LookupTransactionHeader
trial.new_Notes = "this is test plugin using c#";
xrm.AddObject(trial);
xrm.SaveChanges();
}
我更新了我的代码并解决了这个问题:
public void InsertDataUsingLookup(XrmServiceContext xrm, Entity entitiy, ITracingService tracer)
{
new_trialxrmservicetoolkit trial = new new_trialxrmservicetoolkit();
trial.new_name = "testplugin";
trial.new_LookupTransactionHeader = new EntityReference("new_transactionheader", Guid.Parse("5564B5F0-0292-E711-8122-E3FE48DB937B"));
trial.new_Notes = "this is test plugin using c#";
xrm.AddObject(trial);
xrm.SaveChanges();
}
trial.Attributes["new_LookupTransactionHeader"] = new EntityReference("new_transactionheader", new_transactionheaderId-GUID);
您必须像上面那样使用 EntityReference
来设置查找属性。