Resources incide of task

Hello, i am not sure how to work with resources inside of task.
I need change values of units and cost for resources belong to a task.

When i try, .net say that the option are only for read.

I use this code for add resources and change values

For Each dtrowRecursoAR As DataRow In Me.dsCronogramaProject.Recurso.Select(“id=” & idRecurso)
tarea.Assignments.Add((dtrow.Item(“Codigo_Project”)),(dtrowRecursoAR.Item(“Codigo_Project”)))
Exit For
Next

Me.dsCronogramaProject.Recurso has all the resources in the project, but after this, i can’t change the values of cost and units from this resource inside the task.

Can someone help me?


Hi Liz,


Please accept our apology for late reply.

Following code sample reads ResourceAssignments from a sample project file (attached with the post) and displays its existing unit and cost values. Now existing values are updated and then project is saved. Again this project is opened and updated values are displayed to demonstrate the capability of accessing and changing the ResourceAssignments values. Please try the code and let us know your feedback.

ProjectReader reader = new ProjectReader();
Project readProject = reader.Read(“project.xml”);
if (readProject.ResourceAssignments.Count >= 1)
{
ResourceAssignment resAssgn = readProject.ResourceAssignments[0] as ResourceAssignment;
Console.WriteLine("cost = " + resAssgn.Cost);
Console.WriteLine("Units = " + resAssgn.Units);
resAssgn.Units = 3;
resAssgn.Cost = 4;
readProject.ResourceAssignments.RemoveAt(0);
readProject.ResourceAssignments.Add(resAssgn);
}
project.CalcResourceFields();
project.CalcResourceAssignmentIds();
project.CalcResourceAssignmentUids(1);

writer.Write(readProject, “project.xml”, TasksDataFormat.XML);
/////////////////////////////////////////////////////////

//Now again read these properties

ProjectReader projReader = new ProjectReader();
readProject = projReader.Read(“project.xml”);
if (readProject.ResourceAssignments.Count >= 1)
{
ResourceAssignment resAssgn = readProject.ResourceAssignments[0] as ResourceAssignment;
Console.WriteLine("cost = " + resAssgn.Cost);
Console.WriteLine("Units = " + resAssgn.Units);
}

Hi Liz,

You can alter the units and cost associated by using the StandardRate Property of a resource and Units property of a resource assignment, as you can see from the following code:

Dim reader As Aspose.Tasks.ProjectReader = New Aspose.Tasks.ProjectReader
Dim readProject As Aspose.Tasks.Project = reader.Read("project.xml")
If(readProject.ResourceAssignments.Count >= 1) Then
    Dim resAssgn As ResourceAssignment = readProject.ResourceAssignments(0)
resAssgn.Resource.StandardRate = 3
resAssgn.Units = 0.6
readProject.ResourceAssignments.RemoveAt(0)
readProject.ResourceAssignments.Add(resAssgn)
End If
readProject.CalcResourceFields()
readProject.CalcResourceAssignmentIds()
readProject.CalcResourceAssignmentUids(1)
Dim writer As Aspose.Tasks.ProjectWriter = New Aspose.Tasks.ProjectWriter
writer.Write(readProject, "project1.xml", TasksDataFormat.XML)

If this does not meet your requirements, please share your sample code that we can use to reproduce the issue of “the option are only for read” along with your source Project file. We will look into it and assist you further as soon as possible.

I am sorry for this late answer.

I spoke with my boss and he said that i can’t publish all code, but with a little of work (almost cried doing this) I could solve my problem.

Thank you for your help!!!
I’m sorry I bothered you :frowning:

Hi,


It’s good to know that your problem is solved now. Please let us know if we can be of any additional help to you. We will try to assist you as soon as possible.