Updating Task level custom fields

2019-07-23 13:48发布

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!

3条回答
对你真心纯属浪费
2楼-- · 2019-07-23 14:21

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.

查看更多
forever°为你锁心
3楼-- · 2019-07-23 14:31

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.

查看更多
戒情不戒烟
4楼-- · 2019-07-23 14:32

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                     });
查看更多
登录 后发表回答