www.projectwizards.net/

Applescript – Split activity in completed and remaining sub tasks

on 14. May 2012

When managing a project with Merlin you create your tasks and assign them to your resources. As your resources work on their task, you as a PM update your project by entering the actual values. That means, you enter the percentage of the completed work and the actual start date. If updating the tasks in absolute mode, you can enter the actual work or remaining work and duration.

Next time the resource works on the task, and reports its progress to update the data, you enter the new ‘% complete’ and if updating the tasks in absolute mode, the amount of actual work and remaining work so far.

Some users however would like to be able to pause the works on a task, to plan the remaining work sometime later on. This is also a good idea, if wanting to vary the utilization of a resource on a task in time.  So to do so in Merlin, you would need to create two tasks. One for the first part of the works on the task, and a second for the remaining.

To quicken this procedure, we wrote an applescript sample which requires Merlin 2.8.4, and creates the two sub-activities based on the planned and actual values of the task in progress.

If interested, feel free to download, use or modify as you like. 

(* 	Scripting with Merlin 2

	You may incorporate this ProjectWizards sample code into your program(s) without
	restriction.  This ProjectWizards sample code has been provided "AS IS" and the
	responsibility for its operation is yours.  You are not permitted to
	redistribute this ProjectWizards sample code as "ProjectWizards sample code" after having
	made changes.  If you're going to redistribute the code, we require
	that you make it clear that the code was descended from ProjectWizards sample
	code, but that you've made changes.

	Copyright ® 2012 ProjectWizards, Melle, Germany. All rights reserved.

	This script splits tasks in progress into two tasks; a completed and a remaining task.
	It handles assignments and absolute updated actual values defined on the task.
	It does not split assignments, milestones or activity groups.
	It won't split tasks which are completed, or not yet started.
        Just select the task you want to split and call this script.
	Version info: 1.0
	Author: Vicky Stamatopoulou
	Date: May 2012

*)
----

property howthisworksDialogString : "Please select the activity you would like to split into completed and remaining tasks and restart this script."
property TheActivityDialogString : "The activity "
property isPlannedForDialogString : " is planned for "
property splitinto2DialogString : ". Would you like to split it into completed and remaining work tasks?"
property howMuchLeadDialogString : "How much lead/lag in days would you need?"
property errorDialogString : "This script splits only activities having a given work. It cannot split activity groups, assignments, milestones or elements."
property completedNothingToSplitDialogString : "Activity already completed. Nothing to split!"
property notInProgressNothingToSplitDialogString : "Activity hadn't been started yet. Nothing to split!"

tell application "Merlin"

	activate
	set userCanceledOrError to false
	try
		-- get selection
		set myselection to selected object of main window of document 1 as specifier

	on error
		display dialog howthisworksDialogString of me buttons {"OK"} default button 1
		quit me
	end try
	-- get activity information
	tell myselection
		if (class is activity) and (is milestone is false) then
			-- do only for non completed tasks
			set TheCompletness to given actual completion
			if TheCompletness is missing value then
				set TheCompletness to actual completion
			end if
			if (TheCompletness is 1) or (TheCompletness is 0) then
				if TheCompletness is 1 then display dialog completedNothingToSplitDialogString buttons {"OK"} default button 1
				if TheCompletness is 0 then display dialog notInProgressNothingToSplitDialogString buttons {"OK"} default button 1
				quit me
			end if

			-- check groups
			if (count of activities) > 0 then
				set theActs to activities as list
				repeat with a in theActs
					if class of a is activity then
						display dialog errorDialogString buttons {"OK"} default button 1
						exit repeat
					end if
				end repeat

			end if

			set TheActivity to title
			set TheWork to given planned work
			set TheExpectedWork to expected work
			set TheActualWork to actual work
			set remainingWork to given remaining work

		else
			tell application "Merlin" to display dialog errorDialogString buttons {"OK"} default button 1

			quit me
		end if
	end tell

	try
		-- get assignement information
		set TheResource to assigned resource of myselection as list
		set TheResourceName to (names of TheResource) as list
		tell myselection

			set TheActualStart to actual start date
		end tell

	end try
	tell TheWork
		try
			set TheAmount to amount
			set TheFloating to floating as boolean
			set TheRelativeError to relative error as integer
			set TheUnit to unit
		on error
			tell me to display dialog errorDialogString buttons {"OK"}
			quit me
		end try
	end tell

	try
		set dialogResult to display dialog TheActivityDialogString & TheActivity & isPlannedForDialogString & TheAmount & " " & TheUnit & splitinto2DialogString buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel"
	on error number -128
		quit me
	end try

	if button returned of dialogResult is "OK" then

		set TheActualWorkAmount to amount of TheActualWork
		set TheUnit to unit of TheActualWork

		-- Prompt for lead/lag
		set TheLead to display dialog howMuchLeadDialogString default answer ""
		set TheLead to text returned of TheLead
		if TheLead is "" then set TheLead to "0d"

		-- create completed task
		set TheNewOne to (make new activity) as specifier
		tell TheNewOne
			set given planned work to {amount:TheActualWorkAmount, unit:TheUnit, floating:TheFloating, relative error:TheRelativeError}
			set title to "part 1"

			set given actual completion to 1
			set actual start date to TheActualStart

		end tell

		if remainingWork is missing value then
			set remainingWorkAmount to (amount of TheWork) - (TheCompletness * (amount of TheWork))
			set TheUnit to unit of TheWork

		else
			set remainingWorkAmount to amount of remainingWork
			set TheUnit to unit of remainingWork
		end if

		-- create remaining task
		set TheNewSec to (make new activity) as specifier
		tell TheNewSec
			set given planned work to {amount:remainingWorkAmount, unit:TheUnit}
			set title to "part 2"
		end tell

		-- relate activities finish to start
		set TheRelation to relate TheNewOne to TheNewSec
		-- set lead/lag onto linkage
		set buffer duration of TheRelation to TheLead
		repeat with aRes in TheResource
			tell aRes
				-- do assignements
				try
					assign resource to activity TheNewOne
					assign resource to activity TheNewSec
				end try
			end tell
		end repeat

		-- group the activities under the selection
		move TheNewOne to the end of every activity of myselection
		move TheNewSec to the end of every activity of myselection
		tell myselection
			set given planned work to {amount:0, unit:TheUnit, floating:TheFloating, relative error:TheRelativeError}
		end tell
	end if
end tell

Download: split_activity.applescript.zip

If considering putting the script in the scripts folder of Merlin, you should make sure the script is saved in the file format ‘Text’ for it to be able to show currently the duration of the planned work of the selected task. This solves a general Applescript issue mentioned here.

 

Tags: , , , ,

Written by Vicky Stamatopoulou
Vicky Stamatopoulou works at ProjectWizards. She contributes to the MacPM.net blog, Merlin user forums, or other web spaces of ProjectWizards. The content provided is about Merlin or Mac usage, documentation, AppleScripting, or customization. Google+

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment