none
Force CheckIn a Project through code RRS feed

  • Question

  • Hi,

    I have a requirement where I need to CheckIn a project if it is Checked out for more than a specified time interval, and the situation is that any user will not have access to MSPS PWA instance, so I want to run it like a timer job which will run after a particular time interval and do the checkin operation.

    I tried to write the following code, but this is not working.

     static void Main(string[] args)
     {
        forceCheckIn(projId);
    
     }
    
     public static bool forceCheckIn(string projId)
     {
    PublishedProject proj2Edit = null;
     DraftProject dp = null;
        try
        {
          ProjectContext projContext = new ProjectContext(pwaPath);
          projContext.Credentials = CredentialCache.DefaultCredentials;
          Guid projectId = new Guid(projId);
          var projCollection = projContext.LoadQuery(
              projContext.Projects
             .Where(p => p.Id == projectId));
          projContext.ExecuteQuery();
    
          if (projCollection.Count() > 0)
           {
              proj2Edit = projCollection.First();
    
             dp = proj2Edit.CheckOut();
    
             projContext.Load(dp, d => d.Name);
                            
             projContext.ExecuteQuery();
    
          }
    }
    catch(Exception ex){
    dp.publish(true);
    dp.Checkin(true);
    
    }
    }

    The projId passed into the function is the GUID of a checked out project,but this code does not seem to work.

    Please provide some pointers for the same.

    Thanks & regards,

    Divyang Agrawal


    Thursday, December 19, 2013 11:30 AM

Answers

  • hello,

    I would not recommend auto checking in projects that have been checked out for a given time period. What happens if that project is genuinely checked out and being worked on / take offline etc.?

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Thursday, December 19, 2013 1:26 PM
    Moderator
  • Hi,

    Agree with Paul, be very cautious when you 'force check-in' a project, if you need to do it then to be certain that you are only checking in your project look for the check-out session description property on published project object (proj2Edit in you code), in your case it should equal something like: "CSOM Update".

    Otherwise as for your original question, what error are you getting and where does your example fail?

    Regards,


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

    Monday, December 23, 2013 1:24 AM

All replies

  • hello,

    I would not recommend auto checking in projects that have been checked out for a given time period. What happens if that project is genuinely checked out and being worked on / take offline etc.?

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Thursday, December 19, 2013 1:26 PM
    Moderator
  • I also moved this post to the customisation forum.

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Thursday, December 19, 2013 1:27 PM
    Moderator
  • Hi Paul,

    Thanks for the response.

    In order to ensure that I do not check in a project which is genuinely been worked on, I will define a logic to compare the current time and the time, the project was checked out.

    If it is found to be more than 5/6 hrs or more, then only I will check in the project.

    Please provide some pointers, if there is any way I can do it through code or what is the issue with the code above.

    Regards,

    Divyang Agrawal

    Friday, December 20, 2013 5:11 AM
  • So in that scenario, how do you handle projects that are left checked out as they are taken offline? Also, what happens if a PM genuinely has a project checked out and is working on it for over 5 hours? I do honestly think this isn't a good approach.

    What is the issue you are trying to solve?

    Paul


    Paul Mather | Twitter | http://pwmather.wordpress.com | CPS

    Friday, December 20, 2013 8:41 AM
    Moderator
  • Hi,

    Agree with Paul, be very cautious when you 'force check-in' a project, if you need to do it then to be certain that you are only checking in your project look for the check-out session description property on published project object (proj2Edit in you code), in your case it should equal something like: "CSOM Update".

    Otherwise as for your original question, what error are you getting and where does your example fail?

    Regards,


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

    Monday, December 23, 2013 1:24 AM