There are times when project managers assign too many resources to a NetSuite project. When this happens, staff can become confused. The NetSuite dashboard task view and timesheet / expense system will pull a list of project resources from the Project Resource list. Your staff may think they are assigned to a project but since they are not assigned to a project task, they can’t enter time.
Below is a NetSuite SuiteScript program I wrote to clean up the project environment. The algorithm looks for staff resources that have been assigned to the project via the project task assignment (located on the project task record). It then goes to the Project Assignment (located on the Project record) and removes extra project resources that really were not assigned to the project via task definitions.
The SuiteScript was developed as a Mass Update script. Feed it project records and it will clean up the environment. Let me know if you want some help with your unique NetSuite Advanced Projects concern.
SuiteScript Mass Update Code
//------------------------------------------------------------------ //Function: ID019_2_MassUpdate_RemoveBadAssignments //Record: Project //Script Type: Mass Update //Description: This looks at projects and finds staff resource assignments and unassigns them if they have not been assigned to // to any project task //Date: MZ 20120719 //------------------------------------------------------------------ // Psuedo Code: // Get Project ID // Get List of Project Tasks // For Each Get Unique List of assigned resources // Walk List of Project Resources of Type Staff // For each Get List of assigned project resources // if resource is staff but not in task, remove line item // Commit
function ID019_2_MassUpdate_RemoveBadAssignments(rectype, recid) { nlapiLogExecution('AUDIT', 'ID019_2_MassUpdate_RemoveBadAssignments Starting', recid);
// load the project var proj = nlapiLoadRecord('job', recid); if (proj) {
// get lists of tasks assignments for the project
var filters = new Array(); filters[0] = new nlobjSearchFilter('internalid', 'job', 'is', recid);
var columns = new Array(); columns[0] = new nlobjSearchColumn('resource', 'projecttaskassignment')
//search for records var searchresults = nlapiSearchRecord('projecttask', null, filters, columns);
// produce a unique dictionary of resources on the project var goodassignments = {};
// if there is nothing to do, then all the assignments must be bad if (!searchresults) { nlapiLogExecution('AUDIT', 'ID019_2_MassUpdate_RemoveBadAssignments -- no task assignments.'); }
// if we have task assignments, create dictionary if (searchresults) { for ( var i = 0; i < searchresults.length; i++ ) { var result = searchresults[i] var resourceID = result.getValue('resource', 'projecttaskassignment') goodassignments[resourceID] = resourceID } } // for audit purposes, capture the good assignments in the log var key for (key in goodassignments) { if (goodassignments.hasOwnProperty(key)) { nlapiLogExecution('AUDIT', 'ID019_2_MassUpdate_RemoveBadAssignments Found Key ' + key + ':', key); } } // now search the project resource assignment and delete any staff (not managers) that are not good assignments var j = 0 var count = proj.getLineItemCount('jobresources'); for (j=count; j >= 1; j--) {
// only act on this if it is staff (-3 magic number) if (proj.getLineItemValue('jobresources', 'role', j) == -3) { var rID = proj.getLineItemValue('jobresources', 'jobresource', j)
if (goodassignments[rID] == undefined) { nlapiLogExecution('AUDIT', 'ID019_2_MassUpdate_RemoveBadAssignments removing resource assignment ' + j , proj.getLineItemValue('jobresources', 'jobresource', j)); proj.removeLineItem('jobresources',j); }
} } nlapiLogExecution('AUDIT', 'ID019_2_MassUpdate_RemoveBadAssignments commit resource assignment was ' + count , proj.getLineItemCount('jobresources')); nlapiSubmitRecord(proj); } }
Hi Marty,
Thank you for sharing this script, I’m looking to add a project resource to multiple projects based on a custom entity list which contains all current project resources that will run a search for those projects and add the new resource to each project.
Of course, I don’t want to include the internal id for the role because each resource is set to “Staff”. Do you have something similar to this that I could tweak with my custom fields?
Thank you,
Steven
Yes, I could do this. I suspect an approach would be via a Mass Update although other techniques could certainly be used. We could feed in a list of resources and then apply them to your projects. Or, you can feed a list of projects and then feed in the consultant. A helper table could be used to set the role, billing rates, and service items.
Hi Marty,
Thanks for getting back to me. Before I came across your script, I developed a script which includes a saved search to look up the projects of the selected resource in the custom list, and then add the new consultant to each project which got as far as the search.
I think the best way would be to feed the list of projects then feed the consultant based on the selected resource.
Thank you,
Steven