var lookup = new Object();
var lookupValue = new Array();
lookup.id = “Guid Value”;
lookup.entityType = “pricelevel”;
lookup.name = “Record Name”;
lookupValue = lookup;
There are very good articles about this which I have given below.
Is there a way to set the value when the record is saved?.
You cannot use a workflow as the form field is disabled and as you know if a field is disabled on a form then we cannot set a value to it. But using a plugin we can get this done.
We need to use a post create plugin with synchronous mode. I have given below the code for it.
This works correctly and the record is opening with setting a default price list for this field.
public void Execute(IServiceProvider provider)
IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory OrganizationServiceFactory = (IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService OrganizationService = OrganizationServiceFactory.CreateOrganizationService(context.UserId);
Entity target = context.PostEntityImages["Target"] as Entity;
EntityReference ent = new EntityReference("pricelevel", new Guid("D63F72CC-41CB-E111-B129-080027B1770C"));