Retrieving extended attributes and outline codes

Hi,


I have a couple questions.
1. How do I retrieve an extended attribute and selected outline code value for a task or resource
2. what is the significance of an extended attribute with ElementType.Null.

Regards.

Hi Purnima,

Following is the sample code which write/reads extended attribute of a task and displays the Outline code value and Id. Please give it a try and let us know the feedback.

Project project = new Project();
OutlineCodeDefinition textOutline = new OutlineCodeDefinition();
project.OutlineCodes.Add(textOutline);
// add a mask for text field
OutlineMask mask = new OutlineMask();
mask.Type = MaskType.Characters;
textOutline.Masks.Add(mask);
OutlineValue textValue = new OutlineValue();
textValue.Value = "Text value 1";
textValue.ValueId = 1;
textValue.Type = OutlineValueType.Text;
textValue.Description = "Text value descr 1";
textValue.FieldGuid = Guid.NewGuid().ToString().ToUpper();
textOutline.Values.Add(textValue);
OutlineValue textValue2 = new OutlineValue();
textValue2.Value = "Text value 2";
textValue2.ValueId = 2;
textValue2.Type = OutlineValueType.Text;
textValue2.Description = "Text value descr 2";
textValue2.FieldGuid = Guid.NewGuid().ToString().ToUpper();
textOutline.Values.Add(textValue2);
// Add new text3 extended attribute
ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();
taskTextAttr.Alias = "New text3 attribute";
taskTextAttr.FieldId = ExtendedAttributeTask.Text3.ToString("D");
// add a reference to lookup table
taskTextAttr.LookupUid = textOutline.Guid;
taskTextAttr.CfType = CustomFieldType.Text;
project.ExtendedAttributes.Add(taskTextAttr);
// Add new task and assign attribute value
Task task = project.RootTask.Children.Add("New task");
task.Set(Tsk.Start, new DateTime(2016, 7, 4, 8, 0, 0));
task.Set(Tsk.Duration, project.GetDuration(8, TimeUnitType.Hour));
ExtendedAttribute taskAttrText = taskTextAttr.CreateExtendedAttribute();
// add a reference to lookup table value
taskAttrText.ValueGuid = textValue2.FieldGuid;
task.ExtendedAttributes.Add(taskAttrText);
ChildTasksCollector collector = new ChildTasksCollector(); // Create a ChildTasksCollector instance
TaskUtils.Apply(project.RootTask, collector, 0); // Collect all the tasks from RootTask using TaskUtils
foreach (Task tsk in collector.Tasks)
{
    if (tsk.Get(Tsk.Id) == 1)
    {
        ExtendedAttribute extAttrib = tsk.ExtendedAttributes.Where(ext => ext.AttributeDefinition.FieldName == "Text3").FirstOrDefault();
        OutlineCodeDefinition OutlineDef = project.OutlineCodes.Where(def => def.Guid == extAttrib.AttributeDefinition.LookupUid).FirstOrDefault();
        OutlineValue OutlineVal = OutlineDef.Values.Where(val => val.FieldGuid == extAttrib.ValueGuid).FirstOrDefault();
        Console.WriteLine("Value Id = {0}, \nValue = {1}\nDescription = {2}", OutlineVal.ValueId, OutlineVal.Value, OutlineVal.Description);
    }
}

Regarding the second requirement, could you please share more details about null in Element type? Send us any supporting code, files etc. for our analysis.

I dont get ChildTasksCollector and TaskUtils class in my environment… Do I have to include any other dll for the same.

Hi,


There is no other DLL to be included. Please resolve its dependency by including directive of Aspose.Tasks.Util. You can do so by including the following statement at top of your code file.

using Aspose.Tasks.Util;

I get an error at the following line


ExtendedAttributes.Where(ext => ext.AttributeDefinition.FieldName == “Text3”).FirstOrDefault();


Error: Aspose.Tasks.ExtendedAttributeCollection does not contain a defintion for Where…

Hi,


It seems you are using an older version of .NET framework. The code works fine at our end while using .NET Framework 4.5. But if that is not an option with you, you can add another foreach loop inside the first foreach loop to retrieve the information of a specific extended attribute as shown in the following code:

Sample Code:

foreach (ExtendedAttribute extAttr in tsk.ExtendedAttributes)
{
if (extAttr.AttributeDefinition.FieldName == “Text3”)
{
//do something.
}
}

In the following peice of code:

ExtendedAttributeDefinition projCodedef = new ExtendedAttributeDefinition();
projCodedef.CfType = CustomFieldType.Text;
projCodedef.ElementType = ElementType.Null;
projCodedef.FieldId = ExtendedAttributeTask.Text3.ToString(“D”);
projCodedef.FieldName = “Text3”;
proj.ExtendedAttributes.Add(projCodedef);

where ElementType is Null, at what level is the Text3 attribute saved. I am looking for a column where I can store an Id, which should not be visible to the user in MSP.

Hi,


I have tried to perform this task using MSP 2010 but could not hide any column from user. I am afraid that I also could not find any feature in Aspose.Tasks which can be used to hide the information.

Could you please generate such project using MSP and send us the sample project file? We will try to provide further assistance in this regard.

I have not been able to do it MS Project as well

Hi Purnima,


Thank you for providing feedback. I am afraid to share that this feature cannot be provided using Aspose.Tasks. Please feel free to write us back if you have any other query related to Aspose.Tasks.