Inactivate a job on a specific date.

Ever wanted to schedule turning a project to inactive so that no more interviewers can be collected? This article shows you how to login to the DPMServer , find the project and  make it inactive.

The first thing we need to do is to create an mrs script and enter then enter the following code.

Dim dpmAgent,dpmProject,dpmProjects
Dim oArray[10][4],iProjectCount
oArray[0][1] = "J2001"
oArray[0][2] = "25/12/2009"
oArray[0][3] = "Inactive"
oArray[1][1] = "J9001"
oArray[1][2] = "25/12/2009"
oArray[1][3] = "Inactive"

At this stage all we have done is to create some variables to hold specific values. The three constants at the top of the script are used to hold the servername that we will  login into and the username and password that we will use to login with. These names need to be Server Administration logins that have access to the projects that you want to  Inactivate.

next we dimension some variables to hold the objects that will be used to login and also we declare an array that will hold the list of projects that we want to work with. In  the first element we hold the name , this is the PROJECTID , then the date that we would like the Inactivate to happen and then lastly the status we want to change the job to.  There are probably better ways to do this , for example , you could have your list of projects in a SQL database that was updated via a web page, but for the purpose of this  example we are just going to use an array.

Next Type the following code into your script.

Debug.Log("Creating Agent object...")
Set dpmAgent = CreateObject("SPSSMR.DPM.Security.Login.Agent2")
Debug.Log("Login as specified user...")
Set dpmProjects = dpmAgent.Server.Projects

The next bit of code shows us how we can login to the DPMserver as a specified user. This is the same thing that happens when we use DPM Explorer to look at our server settings  and don’t forget you will have to run this on the server itself if your server is hosted outside your network and port 65100 is not opened up. If the Server is in your network  and the port is open you should be able to run this from your desktop.

Now Finish the remaining code,

    iProjectCount = 0
Do While (oArray[iProjectCount][1] <> "")
    On Error Goto ProjectNotFound
      If ( oArray[iProjectCount][2] = format(now(),"ddmmyyyy") )  Then
             Debug.Log("Get the project from DPM...")
      Set dpmProject =  dpmAgent.Server.Projects[oArray[iProjectCount][1]]["Status"] = oArray[iProjectCount][3]
     End If

    On error Goto 0
Debug.Log("Logging out of Agent...")

So what is this doing , well we are looping the array and as soon as we find an array cell that is blank the loop will stop. If the first cell in the array is not empty we will  then check to see if the date specified is today’s date. This is done using the format() command on the now() command to return just the date from the date time. We then compare  that with the value stored in the array and if there is a match we connect to the project and set the status of the project to the value stored in our array in cell  position 3, which in this case is Inactive. Once this has happened and nothing has gone wrong the project counter is incremented by one and we move onto the next item in the  list.

Once you have this code working you can then place you file on the server and create a batch file and schedule it with the windows scheduler. For more information about the  scheduler you can read this article.

The full code for this article can be found in :
http://CodeCorner.SmaterDimensions.Com @ Change status of a Project on specified date

Leave a Comment

%d bloggers like this: