public void AutonumberConfigurationCreateRegistrationsTest() { const string type = "account"; const string field = "accountnumber"; foreach (var entityType in EntitiesToDelete) { DeleteAll(entityType); } DeleteAutonumbersAndRegistrations(type); var autonumber = CreateAutonumber(type, field, "AC", "-", 8); var registration = AutonumberService.GetExistingRegistration(type); Assert.IsNotNull(registration); XrmService.Deactivate(autonumber); registration = AutonumberService.GetExistingRegistration(type); Assert.IsNull(registration); XrmService.Activate(autonumber); registration = AutonumberService.GetExistingRegistration(type); Assert.IsNotNull(registration); XrmService.Delete(autonumber); registration = AutonumberService.GetExistingRegistration(type); Assert.IsNull(registration); }
private void Validate() { // !!!! DONT CHANGE TO PREOPERATION AS RELOADS THROUGH WEB SERVICE !!!! if (IsMessage(PluginMessage.Create, PluginMessage.Update) && IsStage(PluginStage.PostEvent) && IsMode(PluginMode.Synchronous)) { if (FieldChanging(Fields.jmcg_autonumber_.jmcg_parentautonumber, Fields.jmcg_autonumber_.jmcg_parentautonumberlinks, Fields.jmcg_autonumber_.statecode)) { var xrmAutonumber = AutonumberService.GetAutonumber(TargetId); var isChildAutonumber = xrmAutonumber.HasParent; if (isChildAutonumber) { //validate the query var linksToParentString = GetStringField(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks); if (linksToParentString.IsNullOrWhiteSpace()) { throw new NullReferenceException(string.Format("{0} Is Required", GetFieldLabel(Fields.jmcg_autonumber_.jmcg_parentautonumberlinks))); } AutonumberService.ValidateLinksToParent(xrmAutonumber); //validate the parent autonumber a string var parentField = xrmAutonumber.ParentAutonumberField; var parentType = xrmAutonumber.LastLinkTarget; if (XrmService.GetFieldType(parentField, parentType) != AttributeTypeCode.String) { throw new InvalidPluginExecutionException(string.Format("The {0} is required to be for a field of type string", GetFieldLabel(Fields.jmcg_autonumber_.jmcg_parentautonumber))); } //validate has separator if (GetStringField(Fields.jmcg_autonumber_.jmcg_separator).IsNullOrWhiteSpace()) { throw new InvalidPluginExecutionException( string.Format("{0} is required when {1} is populated", GetFieldLabel(Fields.jmcg_autonumber_.jmcg_separator), GetFieldLabel(Fields.jmcg_autonumber_.jmcg_parentautonumber))); } } } if (FieldChanging(Fields.jmcg_autonumber_.jmcg_prefix)) { var theString = GetStringField(Fields.jmcg_autonumber_.jmcg_prefix); if (theString.Any(char.IsDigit)) { throw new InvalidPluginExecutionException(string.Format("{0} cannot contain any numeric characters", GetFieldLabel(Fields.jmcg_autonumber_.jmcg_prefix))); } } if (FieldChanging(Fields.jmcg_autonumber_.jmcg_separator)) { var theString = GetStringField(Fields.jmcg_autonumber_.jmcg_separator); if (theString.Any(char.IsLetterOrDigit)) { throw new InvalidPluginExecutionException(string.Format("{0} cannot contain any alphanumeric numeric characters", GetFieldLabel(Fields.jmcg_autonumber_.jmcg_separator))); } } } }
private void DeleteAutonumbersAndRegistrations(string type) { //delete all autonumbers and registrations for type foreach (var autonumber in AutonumberService.GetAutonumbersForType(type, true)) { XrmService.Delete(Entities.jmcg_autonumber, autonumber.AutonumberId); } while (AutonumberService.GetExistingRegistration(type) != null) { Delete(AutonumberService.GetExistingRegistration(type)); } }
private void CheckPluginRegistration() { if (IsMessage(PluginMessage.Create) && IsStage(PluginStage.PostEvent) && IsMode(PluginMode.Synchronous)) { AutonumberService.RefreshPluginRegistrations(GetStringField(Fields.jmcg_autonumber_.jmcg_entitytype)); } else if (IsMessage(PluginMessage.Update) && IsStage(PluginStage.PostEvent) && IsMode(PluginMode.Synchronous) && FieldChanging(Fields.jmcg_autonumber_.statecode)) { AutonumberService.RefreshPluginRegistrations(GetStringField(Fields.jmcg_autonumber_.jmcg_entitytype)); } else if (IsMessage(PluginMessage.Delete) && IsStage(PluginStage.PostEvent) && IsMode(PluginMode.Synchronous)) { AutonumberService.RefreshPluginRegistrations((string)GetFieldFromPreImage(Fields.jmcg_autonumber_.jmcg_entitytype)); } }
public void AutonumberConfigurationSetFieldTypeTest() { const string type = "account"; const string field = "accountnumber"; foreach (var entityType in EntitiesToDelete) { DeleteAll(entityType); } DeleteAutonumbersAndRegistrations(type); var autonumber = CreateAutonumber(type, field, "AC", "-", 8); var xrmAutonumbers = AutonumberService.GetActiveAutonumbersForType(type); Assert.AreEqual(OptionSets.Autonumber.AutonumberFieldType.String, xrmAutonumbers.First().AutonumberFieldType); }
public override void GoExtention() { AutonumberService.SetAutonumbers(this); }
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(); }