Expand my Community achievements bar.

The next phase for Workfront Community ideas is coming soon. Learn all about it in our blog!

Approval identification within api

Avatar

Level 6
Ok so i'm trying to solve a problem. Workfront doesn't automatically close / submit timesheets natively so we've built a process to run through the system and "submit" all timesheets for approval at noon on mondays. This works great and solves the issue of timesheets being open. Unfortunately users can still recall timesheets and edit them so we may move to "close" timesheets stead of submitting for approval. What i'm up against now is that one department has asked to have managers approve timesheets after they're submitted. I'm trying to figure out if there is a way to dynamically get the user manager, and send the timesheet approval request to them and the original "worker" that we have so i know that the timesheet is getting submitted by the worker, and then sent to the manager for approval. any thoughts or suggestions would be appreciated. Ryan Carroll Integrated Marketing Services
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

2 Replies

Avatar

Level 1
Hi Ryan, My name is Chris from the Developer Support Team here at Workfront. Reading through your post I think I can help out. It sounds like you're looking for 2 separate things, and the latter half is a little unclear to me so I may be able to provide what you need, but also may just need some clarification in case I'm not understanding. Let me know when we get there! The first precedent to set I think is that the this would require some kind of script/middleware to run since this is a Call to gather and store the necessary information which then needs a follow up Call to execute setting 2 Users as the Approver. It sounds like you may already be building something and aware of that, but is something I wanted to be certain to mention. Here is a quick example of a Call that would gather the necessary information in the response for any given Timesheet: https://domain.my.workfront.com/attask/api/v7.0/TSHET/5a7b2e390052689cbc8d426671b4334c/search?fields... Above, the domain has been altered and obviously the GUID of the Timesheet itself is unique to my personal environment (there is also the option of removing the GUID and gathering this for all Timesheets, but this would be inefficient and may need some optimization built into the Call/Script.) But, the rest can be used as a Template. The response would look something like this: { data: {ID: "5a7b2e390052689cbc8d426671b4334c", displayName: "Chris Virostko 05/03/18 - 11/03/18", objCode: "TSHET", user: { ID: "54e3805c00018a964828dccd7d4e62c4", name: "Chris Virostko", objCode: "USER", manager: { ID: "54e3d1050043557903d122fb3c255f35", name: "Daenerys Targaryen", objCode: "USER" }}}} Now that I have this information, I can send a follow-up Call that applies the ID and Name for the Manager I have captured, as well as the User's information to PUT 2 Approvers on to the Timesheet. This call would look something like this: https://domain.my.workfront.com/attask/api/v7.0/TSHET/5a7b2e390052689cbc8d426671b4334c?updates={approvers:[{ID:"54e3805c00018a964828dccd7d4e62c4",name:"Chris Virostko",objCode:"USER"},{ID:"54e3d1050043557903d122fb3c255f35",name:"Daenerys Targaryen",objCode:"USER"}]}&method=PUT&apiKey=redacted If I then run a quick GET to check on the Approvers, the list comes back as such: { data: { ID: "5a7b2e390052689cbc8d426671b4334c", displayName: "Chris Virostko 05/03/18 - 11/03/18", objCode: "TSHET", approvers: [ { ID: "54e3d0a300434e6d7e9a2ee7c8bfe4a2", name: "Jaime Lannister", objCode: "USER" }, { ID: "54e3d1050043557903d122fb3c255f35", name: "Daenerys Targaryen", objCode: "USER" }]}} I hope this helps! Thanks, Chris Chris Virostko Developer Support Engineer, Workfront Support

Avatar

Level 6
Hi Chris, thanks for the response. First let me clear up what we're currently doing then what we're wanting to do. we have a JS app running every monday that is looping through the system finding all "O" timesheets and changing the status to "S" we have hard coded the approver to our api worker where we want to go is: we have a JS app running every monday that is looping through the system finding all "O" timesheets and changing the status to "S" we are dynamically getting the user:manager, adding that as a timesheet approver as well as our hard coded api worker then using the workfront built in notification triggers for Timesheets i.e. timesheet submission to approver to notify the users manager that they need to approve the timesheet. currently here is our worker code: function closeTimesheets(next){ function wkGetOpenTimesheets(){ let testdate = moment().add(-2, 'days').format("YYYY MM DD").replace(/\s/g, '-') return workfront.search('tshet', { status: "O", startDate: testdate, startDate_Mod: "lte" }, [ "ID", "startDate" ]) } function dispatchChunk(sheets, next){ console.log(sheets.length) if(sheets.length > 5){ let chunk = sheets.splice(0, 5) Promise.all(chunk).then(d => { setTimeout(e => dispatchChunk(sheets, next), 5000) }).catch(err => { console.log(err) next(err) }) } else { Promise.all(sheets).then(next).catch(err => { console.log(err) next(err) }) } } workfront.login(wkUser, wkPassword).then(wkGetOpenTimesheets).then(timesheets => { // get all document IDs console.log("timesheets ~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log("~~~~~~~~~~") console.log(timesheets.length) timesheets = timesheets.slice(0,25) let len = timesheets.length, teststart = moment().add(-2, 'days'), sheetpromises = [] while(--len > -1){ let t = timesheets[len] console.log(t.startDate) if(teststart.isAfter(t.startDate)){ sheetpromises.push(workfront.edit('tshet', t.ID, { "status": "S", approverID: "56ec22540027acca2d3013ce01bb6ebf" }, ["*"])) } } dispatchChunk(sheetpromises, next) }).catch(err => next(err)) } **** we have this chunked and we're looping through it a few times to go through everyone so we don't have too many concurrent calls **** Based on what you provided it looks like we'd have to run user by user find the user manager id, and append that - in your example i'm not seeing where you're getting the "Jamie Lannister" - so potentially that is your "hard coded" user? From what i'm seeing in your suggestion we're going to have to re-work our approach on this in order to run through - get all user / manager combos then merge user / manager / hard coded approver then push user / manager / hard coded approver & status change is that accurate? if we do that - once the cron job runs and changes the status to "submitted" would the system default notifications still fire? Ryan Carroll Integrated Marketing Services