本文整理汇总了C#中System.Entity.SetLookupField方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.SetLookupField方法的具体用法?C# Entity.SetLookupField怎么用?C# Entity.SetLookupField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.SetLookupField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitialiseAutonumber
private static Entity InitialiseAutonumber(string type, string field, string prefix, string separator,
int? numberCharacters, Entity parentAutonumber, string linksToParent)
{
var autonumberEntity = new Entity(Entities.jmcg_autonumber);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_entitytype, type);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, field);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_prefix, prefix);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_separator, separator);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_numberofnumbercharacters, numberCharacters);
if (parentAutonumber != null)
{
autonumberEntity.SetLookupField(Fields.jmcg_autonumber_.jmcg_parentautonumber, parentAutonumber);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, linksToParent);
}
return autonumberEntity;
}
示例2: AutonumberForStringStandardAndChildTest
public void AutonumberForStringStandardAndChildTest()
{
const string type = "account";
const string field = "accountnumber";
foreach (var entityType in EntitiesToDelete)
{
DeleteAll(entityType);
}
DeleteAutonumbersAndRegistrations(type);
//create autonumber
var autonumberEntity = CreateAutonumber(type, field, "AC", "-", 8);
var xrmAutonumber = AutonumberService.GetActiveAutonumbersForType(type).First();
//verify the regsitration was cerated for the entity type
var registration = AutonumberService.GetExistingRegistration(type);
Assert.IsNotNull(registration);
//verify autonumbers set for new entities
var account = CreateTestRecord(type);
//AutonumberService.SetAutonumbers(account);
Assert.AreEqual("AC-00000001", account.GetField(field));
account = CreateTestRecord(type);
Assert.AreEqual("AC-00000002", account.GetField(field));
//THIS PART CHECK FOR AUTONUMBER OPTION OF OVERWRITE VALUES ALREADY SET
Assert.IsFalse(xrmAutonumber.OverwriteIfPopulated);
var testOverwriteAccounts = new Entity(type);
testOverwriteAccounts.SetField(field, "SETEXPLICIT");
testOverwriteAccounts = CreateAndRetrieve(testOverwriteAccounts);
Assert.AreEqual("SETEXPLICIT", testOverwriteAccounts.GetStringField(field));
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_overwriteifpopulated, true);
autonumberEntity = UpdateAndRetreive(autonumberEntity, new[] { Fields.jmcg_autonumber_.jmcg_overwriteifpopulated });
testOverwriteAccounts = new Entity(type);
testOverwriteAccounts.SetField(field, "SETEXPLICITAGAIN");
testOverwriteAccounts = CreateAndRetrieve(testOverwriteAccounts);
Assert.AreEqual("AC-00000003", testOverwriteAccounts.GetField(field));
//delete all autonumbers and registrations for type
const string childType = "contact";
const string childField = "firstname";
const string referenceField = "parentcustomerid";
DeleteAutonumbersAndRegistrations(childType);
//child autonumber
var childAutonumberEntity = CreateAutonumber(childType, childField, "CO", "-", 3, autonumberEntity,
referenceField + ":" + type);
//registered
registration = AutonumberService.GetExistingRegistration(childType);
Assert.IsNotNull(registration);
//number set
var testEntity = new Entity(childType);
testEntity.SetLookupField(referenceField, account);
//var thisautonumber = AutonumberService.GetActiveAutonumbersForType(testEntity.LogicalName).First();
//thisautonumber.SetAutonumber(testEntity, XrmService, AutonumberService);
testEntity = CreateAndRetrieve(testEntity);
Assert.AreEqual("CO-00000002-001", testEntity.GetStringField(childField));
testEntity = new Entity(childType);
testEntity.SetLookupField(referenceField, account);
testEntity = CreateAndRetrieve(testEntity);
Assert.AreEqual("CO-00000002-002", testEntity.GetStringField(childField));
XrmService.Delete(childAutonumberEntity);
Assert.IsNull(AutonumberService.GetExistingRegistration(childType));
DeleteMyToday();
}
示例3: AutonumberConfigurationValidateTest
public void AutonumberConfigurationValidateTest()
{
var parentAutonumber = CreateStandardStringAutonumber();
var parentType = parentAutonumber.GetStringField(Fields.jmcg_autonumber_.jmcg_entitytype);
//type not int or string
var autonumber = InitialiseAutonumber("account", "address1_latitude");
VerifyCreateOrUpdateError(autonumber);
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, "numberofemployees");
//prefix numbers
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_prefix, "a1A");
VerifyCreateOrUpdateError(autonumber);
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_prefix, null);
//separator number or digit
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_separator, "1");
VerifyCreateOrUpdateError(autonumber);
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_separator, "a");
VerifyCreateOrUpdateError(autonumber);
autonumber.SetField(Fields.jmcg_autonumber_.jmcg_separator, null);
//create as integer
var integerAutonumber = CreateAndRetrieve(autonumber);
//cannot change type and field
integerAutonumber.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, "firstname");
VerifyCreateOrUpdateError(integerAutonumber);
integerAutonumber.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, "numberofemployees");
//todo jmm cannot change fields
//child autonumber tests
const string childType = "contact";
const string childField = "firstname";
const string referenceField = "parentcustomerid";
DeleteAutonumbersAndRegistrations(childType);
//initialise valid
var autonumberEntity = new Entity(Entities.jmcg_autonumber);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_entitytype, childType);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, childField);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_prefix, "CO");
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_separator, "-");
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_numberofnumbercharacters, 3);
autonumberEntity.SetLookupField(Fields.jmcg_autonumber_.jmcg_parentautonumber, parentAutonumber);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, referenceField + ":" + parentType);
//separator required
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_separator, null);
VerifyCreateOrUpdateError(autonumberEntity);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_separator, "-");
//parent invalid type
autonumberEntity.SetLookupField(Fields.jmcg_autonumber_.jmcg_parentautonumber, integerAutonumber);
VerifyCreateOrUpdateError(autonumberEntity);
autonumberEntity.SetLookupField(Fields.jmcg_autonumber_.jmcg_parentautonumber, parentAutonumber);
//invalid field type
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, "numberofchildren");
VerifyCreateOrUpdateError(autonumberEntity);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_autonumberfield, childField);
//no links
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, null);
VerifyCreateOrUpdateError(autonumberEntity);
//invalid links
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, "abc");
VerifyCreateOrUpdateError(autonumberEntity);
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, "abc:" + parentType);
VerifyCreateOrUpdateError(autonumberEntity);
//valid link
autonumberEntity.SetField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, referenceField + ":" + parentType);
autonumberEntity = CreateAndRetrieve(autonumberEntity);
var parent = CreateTestRecord(parentType);
var child = new Entity(childType);
child.SetLookupField(referenceField, parent);
child = CreateAndRetrieve(child);
var autonValue = child.GetField(childField);
}
示例4: ValidateLinksToParent
public void ValidateLinksToParent(XrmAutonumber autonumber)
{
try
{
var dummyEntity = new Entity(autonumber.EntityType);
var firstLookup = autonumber.FirstLinkLookup;
if (!XrmService.FieldExists(firstLookup, autonumber.EntityType))
throw new NullReferenceException(string.Format("There Is No Field Named {0} On The {1} Record Type", firstLookup, autonumber.EntityType));
if (XrmService.IsLookup(firstLookup, autonumber.EntityType))
{
dummyEntity.SetLookupField(firstLookup, Guid.Empty, autonumber.FirstLinkLookup);
GetParentEntity(dummyEntity, autonumber, new string[0]);
}
}
catch (Exception ex)
{
throw new Exception(string.Format("There Was An Error Validating The {0} Field - {1}", XrmService.GetFieldLabel(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, Entities.jmcg_autonumber), ex.Message), ex);
}
}
示例5: RefreshPluginRegistrations
public void RefreshPluginRegistrations(string entityType)
{
var autonumbers = GetActiveAutonumbersForType(entityType);
if (!autonumbers.Any())
{
while (true)
{
var registration = GetExistingRegistration(entityType);
if (registration == null)
break;
XrmService.Delete(registration);
}
}
else
{
if (GetExistingRegistration(entityType) == null)
{
var newAutonumber = new Entity("sdkmessageprocessingstep");
newAutonumber.SetLookupField("plugintypeid", GetPluginType());
newAutonumber.SetOptionSetField("stage", PluginStage.PreOperationEvent);
newAutonumber.SetLookupField("sdkmessagefilterid", GetPluginFilter(entityType));
newAutonumber.SetLookupField("sdkmessageid", GetPluginMessage());
newAutonumber.SetField("rank", 1);
newAutonumber.SetField("name", string.Format("Autonumber For {0}", XrmService.GetEntityLabel(entityType)));
XrmService.Create(newAutonumber);
}
}
}
示例6: InitialiseWorkflowTask
private static Entity InitialiseWorkflowTask(string name, Entity targetWorkflow, string fetchXml)
{
var entity = new Entity(Entities.jmcg_workflowtask);
entity.SetField(Fields.jmcg_workflowtask_.jmcg_name, name);
entity.SetLookupField(Fields.jmcg_workflowtask_.jmcg_targetworkflow, targetWorkflow);
entity.SetOptionSetField(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype,
OptionSets.WorkflowTask.WorkflowExecutionType.TargetThisWorkflowTask);
entity.SetOptionSetField(Fields.jmcg_workflowtask_.jmcg_periodperrununit,
OptionSets.WorkflowTask.PeriodPerRunUnit.Days);
entity.SetField(Fields.jmcg_workflowtask_.jmcg_periodperrunamount, 1);
entity.SetField(Fields.jmcg_workflowtask_.jmcg_nextexecutiontime, DateTime.UtcNow.AddMinutes(-10));
entity.SetField(Fields.jmcg_workflowtask_.jmcg_on, true);
if (!fetchXml.IsNullOrWhiteSpace())
{
entity.SetField(Fields.jmcg_workflowtask_.jmcg_fetchquery, fetchXml);
entity.SetOptionSetField(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype,
OptionSets.WorkflowTask.WorkflowExecutionType.TargetPerFetchResult);
}
else
{
entity.SetOptionSetField(Fields.jmcg_workflowtask_.jmcg_workflowexecutiontype,
OptionSets.WorkflowTask.WorkflowExecutionType.TargetThisWorkflowTask);
}
return entity;
}