i have a lookup "new_lookuptransactionheader" in my entity "new_trialxrmservicetoolkit". This lookup linked from "new_transactionheader" entity. How can i insert data using c# crm plugin? this mycode:
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();
}
I updated mycode and this solve:
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();
}
You have to use
EntityReference
like above to setup lookup attribute.