Hi,
I’m trying to add a formula to a custom field as outlined in Aspose documentation sample. The formula is added, however, when the project file is opened the field (Text1) where the formula was attached is showing “#ERROR”. It remains this way until I alter the cost value or recalculate the project. Is there any way to prevent “#ERROR” in the custom field as I would not want the end user to have to recalculate the project when first opened? See code below:
Project _project = new Project(“C:\WBSTemplate1.mpp”);// Create a new project task
_project.Set(Prj.NewTasksAreManual, false);
// create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();
attr.FieldId = ExtendedAttributeTask.Text1.ToString(“D”);
_project.ExtendedAttributes.Add(attr);
//
attr.Alias = “Double Costs”;
attr.Formula = “[Cost]*2”;
// add a task to see the result in MSP
Task task = _project.RootTask.Children.Add(“Task”);
// set task cost
task.Set(Tsk.Cost, 100);
// The result of opening of saved project in MSP2010 is in attached screenshot
_project.Save(“C:\WBS\LIVE\1116_16\Project1.mpp”, SaveFileFormat.MPP);
I’ve downloaded a trial version of 9.2.1 of which I have a temporary license for evaluation. I’m using VS 2010 and MS Project 2010.
Thanks, Calvin
Hi Calvin,
Hi Muhammad,
Hi Calvin,
We have investigated this issue and would like to share with you that Microsoft Project automatically calculates
extendedAttribute fields by formula,when you add Custom Fields. The same can be achieved by adding ExtendedAttribute to the task in Aspose.Tasks. Please try the following code sample for your kind reference.
Sample Code:
Project _project = new Project(“C:\WBSTemplate1.mpp”);// Create a new project task
_project.Set(Prj.NewTasksAreManual, false);// create new custom field (Task Text1) with formula which will double task cost
ExtendedAttributeDefinition attr = new ExtendedAttributeDefinition();attr.FieldId = ExtendedAttributeTask.Text1.ToString(“D”);
_project.ExtendedAttributes.Add(attr);
attr.Alias = “Double Costs”;
attr.Formula = “[Cost]*2”;
// add a task to see the result in MSP
Task task = _project.RootTask.Children.Add(“Task”);// set task cost
task.Set(Tsk.Cost, 100);//add ExtendedAttribute to the special Task
ExtendedAttribute taskExtendedAttribute = attr.CreateExtendedAttribute();
task.ExtendedAttributes.Add(taskExtendedAttribute);// The result of opening of saved project in MSP2010 is in attached screenshot
_project.Save(“C:\WBS\LIVE\1116_16\Project1.mpp”, SaveFileFormat.MPP);
Thus, every field used in a formula needs to be initialized before saving to avoiderror in MS Project. For example,
if the formula looks like this:
myTaskDurattr.Formula = “[Number1]+10”;
then the value of Number1 needs to be added to the project to avoid error in MSP.
Sample Code:
ExtendedAttributeDefinition myTaskDurattr = new ExtendedAttributeDefinition();
myTaskDurattr.Alias = “New Duration”;
myTaskDurattr.CfType = CustomFieldType.Duration;
myTaskDurattr.FieldId = ExtendedAttributeTask.Duration10.ToString(“D”);
//using Number1 in fomula
myTaskDurattr.Formula = “[Number1]+10”;
project.ExtendedAttributes.Add(myTaskDurattr);
ExtendedAttribute taskAttrDur = myTaskDurattr.CreateExtendedAttribute();
task.ExtendedAttributes.Add(taskAttrDur);
ExtendedAttributeDefinition myNumber1 = new ExtendedAttributeDefinition();
myNumber1.Alias = “New Number1”;
myNumber1.CfType = CustomFieldType.Number;
myNumber1.FieldId = ExtendedAttributeTask.Number1.ToString(“D”);
project.ExtendedAttributes.Add(myNumber1);
ExtendedAttribute Number1Task = myNumber1.CreateExtendedAttribute();
Number1Task.Value = “10”; //set value
task.ExtendedAttributes.Add(Number1Task);
Hi Kashif,
Hi Calvin,
Thank you for writing to us again.
I have checked the result.mpp file and observed that it shows proper Start10 value in MSP. Later I opened this result.mpp file and saved it again using Aspose.Tasks. This resaved-result.mpp file also displays proper Start10 value and no #ERROR is observed.
Could you please let us know that what steps do you perform after opening the result.mpp file in Aspose.Tasks before saving it again? Please send us the code which you use to update the file, so that we may test it here and provide assistance accordingly.
Hi Kashif,
Hi Calvin,
We have thoroughly examined the code and observed that there is some issue with the formula for Start10 field while using duration in it. If you test the code with the following change, you will also observe the problem. I have logged it under Id TASKS-34536 for further investigation by the product team and you will be automatically notified once any update is received in this regard.
// NOT WORKING CODE
// myTaskStartattr.Formula = “IIf([Summary]=Yes,“NA”,ProjDateAdd([Project Start],[Duration10],“Standard”))”;
// WORKING CODE
myTaskStartattr.Formula = “IIf([Summary]=“Yes”,“NA”,ProjDateAdd([Project Start],“20d”,“Standard”))”;
Hi Kashif,
Hi Calvin,
The issue has been fixed and will be available in the next version of Aspose.Tasks for .NET API. We have requested an ETA from our Product team about this issue and will notify you here as soon as the information is available.
Hi Calvin,
This is to share with you that the fix version of API will be available at the end of this month i.e. April 2016. We’ll update you here as soon as the information is available in this regard.
Hi Kashif,
Hi Calvin,
The issues you have found earlier (filed as TASKS-34536) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.