Can I set a value of new task custom field via PSI?

O

Ogawa

I'm trying to set a value of task custom field via PSI.
(I use Project Server 2007.)

I can update value of task custom field, but I can't
set value of not created task custom field.

I excerpt the following from my code.

WebSvcProject.Project project = new WebSvcProject.Project();

ProjectDataSet projectList =
project.ReadProjectEntities(prjID, 2,
WebSvcProject.DataStoreEnum.WorkingStore);

WebSvcProject.ProjectDataSet updateDataSet = new ProjectDataSet();
WebSvcProject.ProjectDataSet.TaskCustomFieldsRow customRow =
retDataSet.TaskCustomFields.NewTaskCustomFieldsRow();
customRow.CUSTOM_FIELD_UID = Guid.NewGuid();
customRow.PROJ_UID = prjID;
customRow.TASK_UID = taskID;
customRow.TEXT_VALUE = "initial value";
customRow.MD_PROP_UID =
PSLibrary.CustomField.LOCAL_CUSTOM_FIELD_MD_PROP_UID_TASK_TEXT1;
customRow.MD_PROP_ID = PSLibrary.TaskProperties.Text1.WinProjId;
customRow.FIELD_TYPE_ENUM = (byte)PSLibrary.CustomField.Type.TEXT;
updateDataSet.TaskCustomFields.AddTaskCustomFieldsRow(customRow);

project.CheckOutProject(prjID, sessionId, "");
project.QueueUpdateProject(Guid.NewGuid(), sessionId, updateDataSet,
false);
// project.QueueAddToProject(Guid.NewGuid(), sessionId, updateDataSet,
false);
project.QueueCheckInProject(Guid.NewGuid(), prjID, true, sessionId, "");


This code can only work well when TEXT1 field is created already and is
setted value.

In case TEXT1 field isn't created, "SoapException:
LastError=CustomFieldInvalidID" occurred.

Please help me.

Regards.
 
A

Adam Behrle

Ogawa,

I was able to get your code to work by changing the new updateDataSet
you created to the one read from ReadProjectEntities (projectList).
The code looks like this:

//Read entities
ProjectDataSet projectList =
project.ReadProjectEntities(prjID, 2,
TestPSI.pwProjects.DataStoreEnum.WorkingStore);

//Create a new custom fields row
ProjectDataSet.TaskCustomFieldsRow customRow =
projectList.TaskCustomFields.NewTaskCustomFieldsRow();

//Setup the custom field
customRow.CUSTOM_FIELD_UID = Guid.NewGuid();
customRow.PROJ_UID = prjID;
customRow.TASK_UID = taskID;
customRow.TEXT_VALUE = "initial value";
customRow.MD_PROP_UID =
CustomField.LOCAL_CUSTOM_FIELD_MD_PROP_UID_TASK_TEXT1;
customRow.MD_PROP_ID = TaskProperties.Text1.WinProjId;
customRow.FIELD_TYPE_ENUM = (byte)CustomField.Type.TEXT;
projectList.TaskCustomFields.AddTaskCustomFieldsRow(customRow);

//Save
Guid sessionId = Guid.NewGuid();
project.CheckOutProject(prjID, sessionId, "");
project.QueueUpdateProject(Guid.NewGuid(), sessionId, projectList,
false);
project.QueueCheckInProject(Guid.NewGuid(), prjID, true, sessionId,
"");

Hope this helps!

Adam Behrle
QuantumPM
 
A

Antonio Soares

Hello.

I have the same problem, but I’m using the custom field Cost3. Do you solve your problem yet?
Can you help me.

Thanks a lot.


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
W

www.projectserver.cz

Hello.

I have the same problem, but I'm using the custom field Cost3. Do you solve your problem yet?
Can you help me.

Thanks a lot.

EggHeadCafe - .NET Developer Portal of Choicehttp://www.eggheadcafe.com

Hi problem is caused the way you are working with dataset.

1) when custom property do not exist you have to use method
Queueaddtoproject.
2) When custom property exist you have to update existing row and use
method QueueUpdateProject
Sollution:
When you update project dataset use following 2 metods to split your
dataset to 2 parts for operations QueueUpdateProject and
QueueAddToProject
dsProject.GetChanges(System.Data.DataRowState.Modified);
dsProject.GetChanges(System.Data.DataRowState.Added);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top