Read-only mode for extended attribute

I need Text1 lookup options such that once project is created and extended attribute is added with some predefined lookup options, it should allow my customers to open it in MSP and add addtional values for the lookup table. Can you provide me some sample code where extended attribute with lookup table can be added along with the option to add new lookup values in the project? Also I dont want to allow user to add new values in the lookup table. What option should I use? Is there any read-only mode for this purpose?

Maria.Shahid:

As for your inquiry regarding restricting user from adding lookup values, this does not seem to be supported with Microsoft Project and there is no such feature in the API as well.

Seems you dont have information about how MSP does it or you don't want to explore it. See the attached screenshot what I am asking you and tell me how to do it? and support should learn first about API before answering customers.

Hi George,


We are sorry for the inconvenience caused to you.

Following is the sample code which can be used to set the required flag. Please give it a try and share the feedback.
<div style=“color: rgb(0, 0, 0); font-family: “Times New Roman”; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;”>
<div style=“color: rgb(0, 0, 0); font-family: “Times New Roman”; font-size: medium; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;”>

static private void SampleCode()

{

Project project = new Project();

OutlineCodeDefinition textOutline = new OutlineCodeDefinition();

project.OutlineCodes.Add(textOutline);

textOutline.OnlyTableValuesAllowed = true;//NOTE THIS LINE

// add a mask for text field

OutlineMask mask = new OutlineMask();

mask.Type = MaskType.Characters;

textOutline.Masks.Add(mask);

OutlineValue textValue1 = new OutlineValue();

textValue1.Value = “Text value1”;

textValue1.ValueId = 1;

textValue1.Type = OutlineValueType.Text;

textValue1.Description = “Text value descr”;

textValue1.FieldGuid = Guid.NewGuid().ToString().ToUpper();

textOutline.Values.Add(textValue1);

OutlineValue textValue2 = new OutlineValue();

textValue2.Value = “Text value2”;

textValue2.ValueId = 2;

textValue2.Type = OutlineValueType.Text;

textValue2.Description = “Text value descr”;

textValue2.FieldGuid = Guid.NewGuid().ToString().ToUpper();

textOutline.Values.Add(textValue2);

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”);

ExtendedAttribute taskAttrText = taskTextAttr.CreateExtendedAttribute();

task.ExtendedAttributes.Add(taskAttrText);

project.Save(“SavedProject4.xml”, SaveFileFormat.XML);

}

We are examining the latest version of the API for the same functionality to achieve with the methods introduced and will share our feedback with you here soon.

Hi,


That serves the purpose, though I was in need of this using the new methods introduced by the API. I’ll look forward for your feedback about this. Please keep me posted.

Hi George,


You can use the following code that is actually a combination of old and new implementation of the API. This is a workaround method until the feature is fully supported with the new implementation of custom attributes. A ticket with id: TASKSNET-1790 has been logged for provision of the same with the new implementation. We’ll update you here once there is some update available in this regard.

Sample Code:

Project project1 = new Project();
OutlineCodeDefinition textOutline = new OutlineCodeDefinition();
project1.OutlineCodes.Add(textOutline);
textOutline.OnlyTableValuesAllowed = false;//NOTE THIS LINE

//Create an Extended Attribute Definition of Text2 type
var taskExtendedAttributeText2Definition = ExtendedAttributeDefinition.CreateLookupTaskDefinition(CustomFieldType.Text, ExtendedAttributeTask.Text2, “Task Towns Name”);
taskExtendedAttributeText2Definition.LookupUid = textOutline.Guid; // ATTENTION: OLD WAY OF LOOKUP TABLE BINDING.
//Add lookup values for the extended attribute definition
taskExtendedAttributeText2Definition.AddLookupValue(new Value { Id = 1, StringValue = “Town1”, Description = “This is Town1” });
taskExtendedAttributeText2Definition.AddLookupValue(new Value { Id = 2, StringValue = “Town2”, Description = “This is Town2” });

//Add it to the porject’s Extended Attributes collection
project1.ExtendedAttributes.Add(taskExtendedAttributeText2Definition);

//Add a task to the project
var task2 = project1.RootTask.Children.Add(“Task 2”);

//Crate an Extended Attribute from the Text2 Lookup Definition for Id 1
var taskExtendedAttributeText2 = taskExtendedAttributeText2Definition.CreateExtendedAttribute(taskExtendedAttributeText2Definition.ValueList[1]);


//Add the Extended Attribute to task
task2.ExtendedAttributes.Add(taskExtendedAttributeText2);

project.Save(“SavedProject4.xml”, SaveFileFormat.XML);

The issues you have found earlier (filed as TASKSNET-1790) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan