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

Free Support Forum - aspose.com

Resource Sheet

Is it possible to create a custom column or extended attribute on or against the resource sheet or that is able to be applied to the resource sheet?

Hi Sherri,

Thank you for writing to Aspose Support team.

You can use Aspose.Tasks API to add custom field/Extended Attribute for Resource sheet. Please try the following code sample at your end and let us know if you face some issue.

Sample Code:

static void AddExtAttToResource()
{
Project proj = new Project(“New Project 2010.mpp”);

ExtendedAttributeDefinition myNumber1 = null;

if (proj.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Number1.ToString(“D”))) == null)
{
myNumber1 = new ExtendedAttributeDefinition();
myNumber1.Alias = “Age”;
myNumber1.CfType = CustomFieldType.Number;
myNumber1.FieldId = ExtendedAttributeResource.Number1.ToString(“D”);
proj.ExtendedAttributes.Add(myNumber1);
}
else
myNumber1 = proj.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Number1.ToString(“D”)));

ExtendedAttribute Number1Resource = myNumber1.CreateExtendedAttribute();

Number1Resource.Value = “30.5345”;
Resource rsc = proj.Resources.Add(“R1”);
rsc.ExtendedAttributes.Add(Number1Resource);

proj.Save(“Res-ExtAttr.mpp”, SaveFileFormat.MPP);
}

If I comment out the highlighted code I can add the value but my valuelist does not show in the drop down. If I uncomment the highlighted code the drop down values are available but the field is not populated.



static void AddExtAttToResource()
{
AsposeLicense.LoadLicense();
Project proj = new Project(@“C:\JWSG\master.mpp”);

ExtendedAttributeDefinition costTypeDefinition = null;

if (proj.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Text1.ToString(“D”))) == null)
{
costTypeDefinition = new ExtendedAttributeDefinition();
costTypeDefinition.Alias = “CostType”;
costTypeDefinition.ElementType = ElementType.Resource;
costTypeDefinition.CfType = CustomFieldType.Text;
costTypeDefinition.FieldId = ExtendedAttributeResource.Text1.ToString(“D”);
// Required for the value list to show up but causes the value set not to take
//costTypeDefinition.LookupUid = Guid.NewGuid().ToString();
proj.Resources.ParentProject.ExtendedAttributes.Add(costTypeDefinition);

Value namedLaborValue = new Value();
namedLaborValue.Val = Constants.RESOURCE_TYPE.NamedLabor.ToString();
namedLaborValue.Id = 1;
namedLaborValue.Description = Constants.RESOURCE_TYPE.NamedLabor.ToString();
costTypeDefinition.ValueList.Add(namedLaborValue);

Value standardLaborValue = new Value();
standardLaborValue.Val = Constants.RESOURCE_TYPE.StandardLabor.ToString();
standardLaborValue.Id = 2;
standardLaborValue.Description = Constants.RESOURCE_TYPE.StandardLabor.ToString();
costTypeDefinition.ValueList.Add(standardLaborValue);

Value nonLaborValue = new Value();
nonLaborValue.Val = Constants.RESOURCE_TYPE.NonLabor.ToString();
nonLaborValue.Id = 3;
nonLaborValue.Description = Constants.RESOURCE_TYPE.NonLabor.ToString();
costTypeDefinition.ValueList.Add(nonLaborValue);
}
else
{
costTypeDefinition = proj.ExtendedAttributes.GetById(Convert.ToInt32(ExtendedAttributeResource.Text1.ToString(“D”)));
}


ExtendedAttribute CostTypeResource = costTypeDefinition.CreateExtendedAttribute();
CostTypeResource.AttributeDefinition = costTypeDefinition;
CostTypeResource.Value = costTypeDefinition.ValueList[1].Val;
//CostTypeResource.FieldId = costTypeDefinition.FieldId;
//CostTypeResource.ValueGuid = costTypeDefinition.LookupUid;
Resource rsc = proj.Resources.Add(“R1”);
rsc.ExtendedAttributes.Add(CostTypeResource);

proj.Save(@“C:\JWSG\output.mpp”, SaveFileFormat.MPP);
}

Hi Sherri,

We were able to reproduce the issue at our end. There is problem with custom data display from look up id in MSP when the above code is used. The issue has already been logged as TASKS-34550 in our issue tracking system for further investigation by our Product team. We’ll update you here once there is further information available in this regard.

Hi Sherri,

MSP 2007-2013 links object’s extended attribute to lookup value by OutlineValue.ValueGuid. In order to add a value to task or resource from lookup values list, correspondent outline code must be added.

Please try the following code sample at your end and let us know your feedback.

Sample Code:

Project project = new Project(“Project1.mpp”);

ExtendedAttributeDefinition resourceTextAttr = new ExtendedAttributeDefinition();

resourceTextAttr.Alias = “CostType”;

resourceTextAttr.FieldName = “Text1”;

resourceTextAttr.ElementType = ElementType.Resource;

resourceTextAttr.CfType = CustomFieldType.Text;

resourceTextAttr.FieldId = Convert.ToInt32(ExtendedAttributeResource.Text1).ToString(CultureInfo.InvariantCulture);

resourceTextAttr.LookupUid = Guid.NewGuid().ToString();

project.ExtendedAttributes.Add(resourceTextAttr);


OutlineCodeDefinition textCodeDef = new OutlineCodeDefinition();

textCodeDef.Guid = resourceTextAttr.LookupUid;


OutlineMask mask = new OutlineMask();

mask.Level = 1;

mask.Type = MaskType.Characters;

textCodeDef.Masks.Add(mask);


OutlineValue namedLabor = new OutlineValue();

namedLabor.Value = “1.1”;// Constants.RESOURCE_TYPE.NamedLabor.ToString();

namedLabor.ValueId = 1;

namedLabor.FieldGuid = Guid.NewGuid().ToString();

namedLabor.Description = “Desc1.1”;//Constants.RESOURCE_TYPE.NamedLabor.ToString();

namedLabor.Type = OutlineValueType.Number;

textCodeDef.Values.Add(namedLabor);


OutlineValue standardLaborValue = new OutlineValue();

standardLaborValue.Value = “1.2”;//Constants.RESOURCE_TYPE.StandardLabor.ToString();

standardLaborValue.ValueId = 2;

standardLaborValue.Description = “Desc1.2”;//Constants.RESOURCE_TYPE.StandardLabor.ToString();

standardLaborValue.FieldGuid = Guid.NewGuid().ToString();

standardLaborValue.Type = OutlineValueType.Number;

textCodeDef.Values.Add(standardLaborValue);


OutlineValue standardNonLaborValue = new OutlineValue();

standardNonLaborValue.Value = “1.3”;//Constants.RESOURCE_TYPE.StandardNonLabor.ToString();

standardNonLaborValue.ValueId = 3;

standardNonLaborValue.Description = “Desc 1.3”;// Constants.RESOURCE_TYPE.StandardNonLabor.ToString();

standardNonLaborValue.FieldGuid = Guid.NewGuid().ToString();

standardNonLaborValue.Type = OutlineValueType.Number;

textCodeDef.Values.Add(standardNonLaborValue);


project.OutlineCodes.Add(textCodeDef);


ExtendedAttribute thisItem = new ExtendedAttribute();

thisItem.FieldId = resourceTextAttr.FieldId;

thisItem.ValueGuid = standardLaborValue.FieldGuid; // set link


Resource res = project.Resources.Add(“Description”);

res.ExtendedAttributes.Add(thisItem);


Resource res2 = project.Resources.Add(“Res2”);

thisItem = new ExtendedAttribute();

thisItem.FieldId = resourceTextAttr.FieldId;

thisItem.ValueGuid = namedLabor.FieldGuid;

res2.ExtendedAttributes.Add(thisItem);


Resource res3 = project.Resources.Add(“Res3”);

thisItem = new ExtendedAttribute();

thisItem.FieldId = resourceTextAttr.FieldId;

thisItem.ValueGuid = standardNonLaborValue.FieldGuid;

res3.ExtendedAttributes.Add(thisItem);


res.Set(Rsc.Name, “Rsc1”);

res.Set(Rsc.Initials, “R1”);

res.Set(Rsc.Type, ResourceType.Work);

res.Set(Rsc.StandardRate, 0); //res.Set(Rsc.StandardRate, (decimal)r.Value);

res.Set(Rsc.OvertimeRate, 0); //res.Set(Rsc.OvertimeRate, (decimal)r.Value);

res.Set(Rsc.Code, “4”);

res.Set(Rsc.MaxUnits, 24 / 8.0);


//Save the project as MPP project file

project.Save(“Saved.mpp”, SaveFileFormat.MPP);