Updating Task level custom fields

南笙酒味 提交于 2020-01-15 09:03:37

问题


Using CSOM I can see how to use the SetCustomFieldValue method to update custom fields associated to a Project, but is it not possible to do this for a task within Project Online? I don't see anything that would allow this but it does list in the documentation this should be possible.

Thanks!


回答1:


Have you looked at this thread? Use CSOM to update project's custom fields

It's Project level but it may provide some further clues. Actually, there's task level code at the bottom of that post so hopefully, that's what you need.




回答2:


I've also searched for a way of updating task level custom fields, but couldn't find a solution. For this and some other reasons I've decided to do this by implementing a projectdrilldown extension. This means to update the value directly in the project grid and let project server do the rest of the internal processing:

       _grid=window.projectDrilldownComponent.get_GridSatellite(); // get the grid

       // Update the datavalue of a column (taskfield) 
       _grid.WriteDataValueByKey(...)
       // Update the localizedvalue of a column (taskfield)
       _grid.WriteLocalizedValueByKey(rec_key, fieldkey, fieldvalue,
                function () {
                    console.log("Post Update task:" + rec_key);
                    cbSuccess();                        // callback after update                     });



回答3:


I can give you a JSOM example to do this:

var projContext = PS.ProjectContext.get_current();    
var projects = projContext.get_projects();
var project = projects.getByGuid(projUid).get_draft();
var tasks = project.get_tasks();

var task = tasks.getByGuid(taskUid);

task.set_item(cfIntName, newValue);

var queueJob = project.update();

projContext.waitForQueueAsync(queueJob, 60, 
    Function.createDelegate(this, function(res) {
        // Publish project here
    }), function(error) {

    console.error(error);        
}); 

That should be complete (though I pulled it from a script, so check the success / failure handlers which I truncated)

From memory poking around in the CSOM there is no "set_item(cf, val)" helper method to use, but it was similar, I think the property is set on the object instance via an indexer, e.g.:

(sudo c# code)

var draftTask = [get task instance];
draftTask[cfInternalName] = "Some value";

etc.

If that doesn't help then you can always reflect the ProjectServer.Client.DLL and you'll see the internal implementation of "SetCustomFieldValue" which is not publicly exposed.

Hope that helps someone.



来源:https://stackoverflow.com/questions/25853398/updating-task-level-custom-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!