miércoles, 24 de diciembre de 2008

Create automatic approval rules for all users

Hi,
I've got a test environment where we must use only "Outlook Add In" to update the projects. As you know, there are 2 big problems when you try to do it.
The first one is that approval rules are created for each supervisor user. So, if we have got 350 users we have to generate a tutorial and every user has to configure his own rules.
The second one is when you update a project from "Outlook Add In" or "My Tasks" section, the project is not published, so the update is not visible from the Project details.

We are going to solve the first issue creating an automatic rule in the Publish Database. Of course, YOU MUST NOT touch production databases unless you will like to lost Microsoft Support. (The next code modifys direcly Project server Publishing database).

To create automaticaly a rule you can make a console program like this:

static void Main(string[] args)
{
connectionString = ""; //Connection string
SqlConnection connCosts = new SqlConnection(connectionString);
SqlCommand cmdCosts = new SqlCommand("Select res.RES_UID from MSP_RESOURCES as res ", connCosts);
SqlDataAdapter daCosts = new SqlDataAdapter(cmdCosts);
DataTable dtCosts = new DataTable();
daCosts.Fill(dtCosts);
foreach (DataRow dr in dtCosts.Rows)
{

SqlConnection connUsr = new SqlConnection(connectionString); SqlCommand cmdUsr = new SqlCommand("Select RULE_UID from MSP_RULES where RES_UID_MGR ='" + new Guid(dr[0].ToString())+"'", connUsr);
SqlDataAdapter daUsr = new SqlDataAdapter(cmdUsr);
DataTable dtUsr = new DataTable();
daUsr.Fill(dtUsr);
if (dtUsr.Rows.Count == 0)
{
//If the rule was not created for the user create it
SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = connectionString; myConnection.Open();
string insertstring = "INSERT into MSP_RULES(RULE_UID,RES_UID_MGR,RULE_NAME,RULE_IS_AUTOMATIC,RULE_TYPE,RULE_CONDITION_TYPE,RULE_IS_EXCL_PROJECT,RULE_IS_EXCL_RESOURCE,RULE_IS_EXCL_DELEGATEE,CREATED_DATE,MOD_DATE) values('" + Guid.NewGuid() + "','" + new Guid(dr[0].ToString()) + "','" + "Approve All" + "','" + "True" + "','"+ "5" +"','"+"0',"+"'True','True','True','"+DateTime.Now+"','"+DateTime.Now+"' ) "; SqlCommand comando = new SqlCommand(insertstring, myConnection);
comando.ExecuteNonQuery();
myConnection.Close();
}
}

}


If you activate it after ervery sinchronization It would create rules for all the new users and let other rules as the same.