AllowedValuesAttribute constraint On Setting Task Formula

Discussions related to custom development with Select.
Post Reply
timothymeyer16
Posts: 16
Joined: Mon Jun 14, 2021 9:47 am

AllowedValuesAttribute constraint On Setting Task Formula

Post by timothymeyer16 »

Good Morning.


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());
                    }
             }
        }

timothymeyer16
Posts: 16
Joined: Mon Jun 14, 2021 9:47 am

Re: AllowedValuesAttribute constraint On Setting Task Formula

Post by timothymeyer16 »

As an update, I played around with some values, but to no avail.

Across orders and fields, the consistent error I am receiving is:

Code: Select all

System.OperationCanceledException: The order has unresolved errors. Any outstanding errors must be resolved before the order can be saved.
   at SoftPro.OrderTracking.Client.Orders.OrderStoreProvider.EnsureNoErrors(IOrder order)
   at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.BeginApplyChanges(IOrder order, IProgress`1 progress)
   at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.ApplyChanges(IOrder order)
   at BulkAddOrderContacts.Form1.Test() in C:\_C# Projects\Windows Forms\BulkAddOrderContacts\BulkAddOrderContacts\test.cs:line 76
   
Again, the formulas and orders work perfectly well when entered manually.
BobRichards
Posts: 1149
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: AllowedValuesAttribute constraint On Setting Task Formula

Post by BobRichards »

Ultimately the problem is that one of the parameters required for SetFormula is a Guid that specifies what language parser is required to process the formula. We build extensibility into the product from the start. Try this:

Code: Select all

// This guid is magic!
Guid FormulaLanguage = new Guid("1AB0C637-DB71-4461-B0E2-13BA9DDEFF0C");

IOrderItem checklistTask = ...
checklistTask.SetFormula("Status", FormulaLanguage, "Value = 'NA'");
Bob Richards, Senior Software Developer, SoftPro
timothymeyer16
Posts: 16
Joined: Mon Jun 14, 2021 9:47 am

Re: AllowedValuesAttribute constraint On Setting Task Formula

Post by timothymeyer16 »

Indeed, it is a magic Guid!!

Thanks Bob!
Post Reply