We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Custom field with custom values in dropdown

Hi,


I want to create a custom field in MS Project with a custom list of static dropdown values. Is it possible to do so from Aspose Task, if so, how?


Regards
This Sample works great to define custom attributes and value lists. can you please show a sample as to how we can select a value from the value list programmatically?

Hi,


You can use the ValueGuid property of the Task Extended Attribute to select a value from the value list programmatically. Please modify the following line:

// add a reference to lookup table value
taskAttrText.ValueGuid = textValue.FieldGuid;

in your code sample to:

// add a reference to lookup table value
taskAttrText.ValueGuid = textValue2.FieldGuid;

and you will see that now the second value from value lists has been assigned to the text extended attribute. Please let us know your feedback if you have any further query in this regard.
Thanks Kashif Iqbal.

In a case where we are using ExtendedAttributes only and not OutlineCodes how to select a value programmatically, here is what i have done without any luck

taskTypeTextAttr = project.ExtendedAttributes.FirstOrDefault(ea => ea.FieldId == Convert.ToInt32(ExtendedAttributeTask.Text27).ToString());
if (taskTypeTextAttr == null)
{
// Add new text extended attribute and one text value
taskTypeTextAttr = new ExtendedAttributeDefinition();
taskTypeTextAttr.Alias = "TaskType";
taskTypeTextAttr.FieldName = "Text27";
taskTypeTextAttr.ElementType = ElementType.Task;
taskTypeTextAttr.CfType = CustomFieldType.Text;
taskTypeTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeTask.Text27).ToString();
taskTypeTextAttr.LookupUid = PhaseId;

project.ExtendedAttributes.Add(taskTypeTextAttr);
Value val1 = new Value();
val1.Id = 1;
val1.Description = "Project Phase";
val1.Val = "Phase";
taskTypeTextAttr.ValueList.Add(val1);
Value val2 = new Value();
val2.Id = 2;
val2.Description = "Process Step to Check quality";
val2.Val = "Process Step";
taskTypeTextAttr.ValueList.Add(val2);

Value val3 = new Value();
val3.Id = 3;
val3.Description = "Sales to delivery handoff";
val3.Val = "S2D";
taskTypeTextAttr.ValueList.Add(val3);
}

var projectPhase = rootTask.Children.Add(phase);
//Add custom attribute
var phaseData = taskTypeTextAttr.CreateExtendedAttribute();
phaseData.Value = phaseData.AttributeDefinition.ValueList[0].Val;
projectPhase.ExtendedAttributes.Add(phaseData);

Can you help identify the issue?

Hi Ujwal,


Thank you for writing to Aspose support team.

Create tasks and extended attributes using Microsoft Project, set look up values for the new extended attribute and save the project as XML. If you open this XML file in Notepad and observe the contents, you will observe that Outline codes are there. I am afraid that I could not find any option using Aspose.Tasks to add extended attributes with lookup value without using the Outline code. Please give a try to the following sample code which creates extended attribute Text27.

Project project = new Project();<o:p></o:p>

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 text27 extended attribute

ExtendedAttributeDefinition taskTextAttr = new ExtendedAttributeDefinition();

taskTextAttr.Alias = "New text27 attribute";

taskTextAttr.FieldId = ExtendedAttributeTask.Text27.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 = textValue.FieldGuid;

task.ExtendedAttributes.Add(taskAttrText);

//project.Save(path + "SavedProject.mpp", SaveFileFormat.MPP);

project.Save(path + "SavedProject.xml", SaveFileFormat.XML);

Thanks again for the sample it works fine.

Now, i am facing a challenge reading the value right after saving without any modification. I am able to read the exntended attribute but the values are all null.

Can you please help here?

var customTaskTypeAttr = task.ExtendedAttributes.FirstOrDefault(ea => ea.AttributeDefinition.FieldId == Convert.ToInt32(ExtendedAttributeTask.Text27).ToString());
if (customTaskTypeAttr != null)
{
var valueGuid = customTaskTypeAttr.ValueGuid;
if (!string.IsNullOrWhiteSpace(valueGuid))
{
// My Code never enters here as the valueGuid is always null
}
}

Tried using ChildTasksCollector as described here https://forum.aspose.com/t/6035

It works fine when the same Project instance is being used, but when we save the project and reload the project, i am not able to read the custom attribute values and the ValueGuid is defaulting to null.

I tried saving it as XML file and i can see the value guid stored, not sure if this is a bug or i am doing something incorrect, can you please help.

Hi Ujwal,


I have tested the attached sample code using Aspose.Tasks for .NET 9.4.1 but could not re-produce the issue. Could you please share which version of Aspose.Tasks are you using? Please give a try to the attached code using latest version and share the feedback.


As mentioned it works in the same project instance. If you modify your sample to save the project as MPP and reload the MPP and then read the custom attribute, it doesn't show the value.

Uncomment the lines to save the project as MPP and reload the project (MPP) in the screenshot and you can see that valueGuid is returned as empty

Hi Ujwal,


Thank you for providing more details. This issue is reproduced and logged under Id: TASKSNET-1593 for further investigation by the product team. You will be automatically notified once any update is received in this regard.
Thanks Kashif.

Right now this is a blocker bug for us to go ahead with this product. Any timelines on when we can get a new version would be appreciated to help us plan.

Hi Ujwal,


As this issue is recently logged therefore it is still there in queue for the product team analysis. You will be notified once the product team analyzes this issue and provides any feedback.

The issues you have found earlier (filed as TASKSNET-1593) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.