Below code will show you how to update custom column of Task in Project Online using JavaScript Object Model
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
var projContext; var projects; var project; var draft_project; var tasks; var task; var customfields; var ProjectId = '<guid here>'; //Guid of the Project to Be Updated SP.SOD.executeOrDelayUntilScriptLoaded(runMyCode, "PS.js"); //Load PS.js function runMyCode() { //Create the ProjectContext object projContext = new PS.ProjectContext('<pwa site>'); //Project List information will be placed inside projects variable projects = projContext.get_projects(); //Signal the information that is going to be loaded projContext.load(projects); //Send the request to the server projContext.executeQueryAsync(LoadProject, QueryFailed); } function LoadProject() { //Create variable that will hold specific project information project = projects.getById(ProjectId); projContext.load(project); projContext.executeQueryAsync(ProjectLoadFinished, QueryFailed); } function ProjectLoadFinished() { //The project Variable contains published information // alert(project.get_name()); //In order to change the project you need to Checkout the Project draft_project = project.checkOut(); GetTasks(); } function GetTasks() { tasks = draft_project.get_tasks(); projContext.load(tasks); projContext.executeQueryAsync(TasksLoadFinished, QueryFailed); //var jobUid = draft_project.update(); //projContext.waitForQueueAsync(jobUid, 3600, PublishAndCheckIn); } function TasksLoadFinished() { task = tasks.getByGuid('<task guid>'); //GUID of Task projContext.load(task); projContext.executeQueryAsync(TaskLoadFinished, QueryFailed); } function TaskLoadFinished() { //customfields = task.get_customFields(); //projContext.load(customfields); task.set_item('<custom Column internal name>', 'This is a testing method'); //set value here var jobUid = draft_project.update(); projContext.waitForQueueAsync(jobUid, 3600, PublishAndCheckIn); //projContext.executeQueryAsync(CustomFieldsLoadFinished, QueryFailed); } function CustomFieldsLoadFinished() { } function PublishAndCheckIn(response) { Log("Publishing and Checkin in"); var jobUid2 = draft_project.publish(true); projContext.waitForQueueAsync(jobUid2, 3600, FinalMessage); } function FinalMessage(response) { console.log(response); } function QueryFailed(error) { } }); |
For Lookup values update is as follows:
1 |
task.set_item('<custom field internal name>',['<lookup value>']); //without "Entry_" |
To get the internal name of a Task Custom Field below is the endpoint.
1 |
<site>/pwa/_api/ProjectServer/Projects('<guid>')/Draft/Tasks('<guid>')/CustomFields('<guid>')/InternalName |
Reference Link: http://sharepoint.stackexchange.com/questions/118695/update-custom-field-in-task-project-online
Note: This code will update the project plan without going to approval center
1 thought on “Update Custom Column of Task in Project Online using JSOM”