none
Project Server 2010 custom workflow - get project name RRS feed

  • Question

  • I need to get the ProjectName of the current project in a custom workflow. I know PSI has a function to get the Project Name from a GUID.  Are there any other options?

    Monday, December 30, 2013 4:23 PM

Answers

  • Hi David,

    I just checked and you can definitely get Project Name from the ReadProjectProperty activity that comes with Project Server workflows by default. Make sure you follow this article to add all the project workflow activities to your project:

    http://msdn.microsoft.com/en-us/library/office/ee767686(v=office.14).aspx

    Then from the ReadProjectProperty activity you can find Project Name in the PropertyName parameter.

    Regards,


    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    • Marked as answer by davidlcrooks Tuesday, January 7, 2014 5:32 PM
    Tuesday, January 7, 2014 2:13 AM
  • Thanks again for the prompt reply, Martin!

    As usual for MSFT, the documentation for using the ReadProjectProperty activity sucks!

    I added the ReadProjectProperty activity towards the beginning of my workflow.  I just wanted to get the PROJ_NAME and store it in a variable. 

    First, I defined the variable projName as a public string[] as the PROJ_NAME comes in as an array.

    In the ReadProjectProperty activity the PropertyName is PROJ_NAME, PropertyValues has to be defined by double clicking on the yellow database icon and selecting the projName variable I created in the code. Then, of course, have to set the WorkflowContext like the rest of the activities.

    At last in the code, I can use projName[0] for the name of the project. 

    Thanks, Microsoft!



    • Marked as answer by davidlcrooks Tuesday, January 7, 2014 5:32 PM
    • Edited by davidlcrooks Tuesday, January 7, 2014 5:50 PM
    Tuesday, January 7, 2014 5:32 PM

All replies

  • HI David,

    i am assuming that you may have your reasons to seek for an alternative, as through PSI its equally easy as well since WF initiated from within the project context as well.

    the other option could be to use SQL query from within your custom workflow code to fetch the project name based on project GUID. please find below code snippet for reference:

     string ConnectionString = "Data Source=sp2010;Initial Catalog=ProjectServer_Reporting;Integrated Security=True";
                SqlConnection con = new SqlConnection(ConnectionString);
                string sql = "Select ProjectName From MSP_EpmProject_UserView Where ProjectUID = @ProjectUID";
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                da.SelectCommand.Parameters.AddWithValue("@ProjectUID", projectSequence1.WorkflowContext.ProjectUid);
                DataTable dt = new DataTable();
                con.Open();
                da.Fill(dt);
                con.Close();
                return dt;

    this will return a datatable with project name sitting at [0] row of datatable. 

    hope this helps.


    Khurram Jamshed - MBA, PMP, MCTS, MCITP ( Blog, Twitter, Linkedin )
    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.

    • Marked as answer by davidlcrooks Tuesday, December 31, 2013 1:40 PM
    • Unmarked as answer by davidlcrooks Friday, January 3, 2014 7:10 PM
    Tuesday, December 31, 2013 7:49 AM
  • Khurram,

    I am open to looking at some of PSI code.  I would need to use a configuration list to store the database information as the workflow will be running on different servers.  Thanks!

    David L. Crooks

    Tuesday, December 31, 2013 1:43 PM
  • In my custom workflow, how can I get the project GUID?  Thanks!

    David L. Crooks

    Friday, January 3, 2014 7:11 PM
  • Hi David,

    You can get a some information on the current project from the 'ProjectWorkflowContext' object that is available in all Project Server workflows once started, that includes definitely the ProjectUID and probably even Project Name.

    Any other custom field values can be obtained via the project specific workflow activities (e.g. ReadProjectProperty) so have a look at those first before you try to use PSI as in many cases using PSI should not be required in a workflow.

    Hope that helps,


    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    Monday, January 6, 2014 12:26 AM
  • Thanks Martin for the prompt reply!

    I confirmed that the Project Name IS NOT in the ProjectWorkflowContext object.  The ProjectUID is there and I now need to get the name.  Of course, all I can find are functions to get the GUID from the name...

    What bugs me is that I am using the New Project PDP with the Project Name field and have not figured out how to retrieve that value within the custom workflow...

    Any ideas?

    David L. Crooks


    Monday, January 6, 2014 1:47 PM
  • Hi David,

    I just checked and you can definitely get Project Name from the ReadProjectProperty activity that comes with Project Server workflows by default. Make sure you follow this article to add all the project workflow activities to your project:

    http://msdn.microsoft.com/en-us/library/office/ee767686(v=office.14).aspx

    Then from the ReadProjectProperty activity you can find Project Name in the PropertyName parameter.

    Regards,


    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    • Marked as answer by davidlcrooks Tuesday, January 7, 2014 5:32 PM
    Tuesday, January 7, 2014 2:13 AM
  • Thanks again for the prompt reply, Martin!

    As usual for MSFT, the documentation for using the ReadProjectProperty activity sucks!

    I added the ReadProjectProperty activity towards the beginning of my workflow.  I just wanted to get the PROJ_NAME and store it in a variable. 

    First, I defined the variable projName as a public string[] as the PROJ_NAME comes in as an array.

    In the ReadProjectProperty activity the PropertyName is PROJ_NAME, PropertyValues has to be defined by double clicking on the yellow database icon and selecting the projName variable I created in the code. Then, of course, have to set the WorkflowContext like the rest of the activities.

    At last in the code, I can use projName[0] for the name of the project. 

    Thanks, Microsoft!



    • Marked as answer by davidlcrooks Tuesday, January 7, 2014 5:32 PM
    • Edited by davidlcrooks Tuesday, January 7, 2014 5:50 PM
    Tuesday, January 7, 2014 5:32 PM
  • Now I need the project's GUID and when I use ProjectWorkflowContext all I get are zeros (0000000-0000-0000-0000-00000000).

    prjContext = new Microsoft.Office.Project.Server.Library.ProjectWorkflowContext();

    string prjUid = prjContext.ProjectUid.ToString()

    Like I said, prjUid is all zeros.  Why?

    David L. Crooks

    Thursday, January 9, 2014 2:09 PM
  • Hi David,

    Actually my you need to use the workflow context which the workflow is instantiated with which contains all of the workflow properties.

    The projectSequence1 should be the first activity (or container) in your Workflow and it will contain the data for the current project.

    See step 5 on the 1st procedure here: http://msdn.microsoft.com/en-us/library/ee767701(v=office.14).aspx

    Once done then you will have access to: projectSequence1.WorkflowContext.ProjectUid

    Regards,


    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    Thursday, January 9, 2014 10:37 PM
  • Thanks for the response, Martin!

    Yes, of course, I have projectSequence1.

    !!!!! I just figured out within the code how to use the command:

    Guid prjGuid = projectSequence1.WorkflowContext.ProjectUid;

    I don't understand why MSFT could not have included it in the ReadProjectProperty activity????

    Thanks for info! I owe you one!

    David L. Crooks




    Friday, January 10, 2014 2:50 PM