I am receiving the following error when attempting to set a simple formula into a Checklist Task Status field.
Code: Select all
[07:13 | Entry:] Err2: SoftPro.ClientModel.ValidationException: The specified value violates the SoftPro.ClientModel.Validations.AllowedValuesAttribute constraint.
---> System.Exception: The specified value violates the SoftPro.ClientModel.Validations.AllowedValuesAttribute constraint.
at SoftPro.ClientModel.Validations.ValidationAttribute.Validate(ValidationContext contextMode, ValidationAttribute[] constraints, ITypeDescriptorContext context, Object value)
at SoftPro.EntityModel.ValidationConstraintInstance.Check(Object value)
--- End of inner exception stack trace ---
at SoftPro.EntityModel.ValidationConstraintInstance.Check(Object value)
at SoftPro.EntityModel.ValidationConstraintInstance.Check()
at SoftPro.EntityModel.EntityExecutionContext.CheckConstraints()
at SoftPro.EntityModel.EntityExecutionContext.Dispose(Boolean completed)
at SoftPro.EntityModel.EntityExecutionContext.Scope.Dispose()
at SoftPro.EntityModel.Entity`1.SoftPro.EntityModel.IEntity.SetFormula(String path, Formula formula)
at Task.SoftPro.OrderTracking.Client.Orders.IOrderItem.SetFormula(String , Guid , String )
at BulkAddOrderContacts.Form1.UpdateAllTasksWithCode(IOrder order, String taskCode, String field, Object newValue, Boolean isFormula) in C:\_C# Projects\Windows Forms\BulkAddOrderContacts\BulkAddOrderContacts\test.cs:line 130
at BulkAddOrderContacts.Form1.Test() in C:\_C# Projects\Windows Forms\BulkAddOrderContacts\BulkAddOrderContacts\test.cs:line 58
Please note I can successful Set Property value, and remove the formula, but I can not set a simple formula.
My code is as follows:
newValue == "Value = 'NA'" // This works as a formula when entered manually
Code: Select all
public static void UpdateAllTasksWithCode(IOrder order, string taskCode, string field, object newValue, bool isFormula)
{
// Pull Taks
IList tasks = (IList)order.GetProperty("Tasks");
// Iterate over tasks
foreach (IOrderItem task in tasks)
{
// Identifiy target tasks by code
if (task.GetProperty("Code").ToString().ToLower() == taskCode.ToLower())
{
// Clear formula
task.ClearFormula(field);
// Set Guid / Formula
//string random12 = Random12();
Guid SelectFormula = new Guid($"1CB0C737-DB71-4461-B1E3-FC928517BCF9"); // create random 12
task.SetFormula(field, SelectFormula, newValue.ToString());
}
}
}