locked
How to work with vacations use PSI ? RRS feed

  • Question

  • Hello! 
    How can I work (add\edit\delete) with resources vacations by PSI? Give a code example (C#), if it is possible.
    Tuesday, August 28, 2012 5:04 AM

Answers

  • Hi Nik--

    Please see a sample code:

    static void AddExceptionToResourceCalender()
            {
    
               Guid ResUid = new Guid("26589954-f4c7-4368-88a0-81e783153d85");
                // //Update Resource data
    
                ResourceSvc.ResourceDataSet rds = new ResourceSvc.ResourceDataSet();
                ResourceSvc.Resource res = new ResourceSvc.Resource();
                res.UseDefaultCredentials = true;
    
                ResourceSvc.ResourceDataSet resourceDs = new ResourceSvc.ResourceDataSet();
                resourceDs = res.ReadResource(ResUid);
                res.CheckOutResources(new Guid[] { ResUid });
                ResourceSvc.ResourceDataSet.CalendarExceptionsRow cer = resourceDs.CalendarExceptions.NewCalendarExceptionsRow();
    
                cer.Name = "Sick";
                cer.RES_UID = ResUid;
                cer.Start = DateTime.Now.AddDays(3);
                cer.Finish = DateTime.Now.AddDays(3);
                cer.RecurrenceType = 0;
                cer.RecurrenceFrequency = 1;
    
                resourceDs.CalendarExceptions.Rows.Add(cer);
                
                res.UpdateResources(resourceDs, false, true);
             
    }

    It works for me without any issue.

    Thanks,


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 8:41 AM
  • Sorry, but it's not all, i need to update and delete some calendarException row.
    How i can do that?

    I found the row and would like to remove it:

    ResourceDataSet.CalendarExceptionsRow cer = resDS.CalendarExceptions.First(x => x.RES_UID == resRow.RES_UID);
    
    resDS.CalendarExceptions.RemoveCalendarExceptionsRow(cer);
    
    resClient.UpdateResources(resDS, false, true);

    And is not working.


    Nik

    Updatng resource calendar exceptions is also not possible using PSI (see http://social.technet.microsoft.com/Forums/en-US/project2010custprog/thread/078b7e12-4b33-4bb7-bcc7-ff732b96158a)

    You would have to use client side coding to set the work week for a resource calendar.

    Though you can create an exception in Res Cal but editing (Update/delete) is not possible using PSI.  http://msdn.microsoft.com/en-us/library/office/ee767706.aspx

    Defining or editing local base calendars or resource calendars, including calendar exceptions.


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 1:12 PM

All replies

  • Hi there--

    I have recently written a code but currently not able to access the Dev server due to N/W issue. Will share the code once I am able to access server.
    Steps:
    1. Used the Resource Web service & Read resource method to get the Resourcedataset
    http://msdn.microsoft.com/en-us/library/office/gg229695
    http://msdn.microsoft.com/en-us/library/office/gg238402

    2. Used the ResourceDataSet.CalendarExceptionsDataTable Class to get the calendar exception of resource
    3. Used the AddCalendarExceptionsRow to add the Exceptions.
    http://msdn.microsoft.com/en-us/library/office/gg224188

    Hope that helps.


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Tuesday, August 28, 2012 5:31 AM
  • Hi Amit!

    I tried that:

      • Create ResourceClient object;
      • Read all resources and get CalendarExceptions data table;
      • Put new CalendarException row into CalendarException data table;

    And i don't understand how to update or save this changes.

    Code sample:

    ResourceClient resClient;
    CreateEndpoints(out resClient);
    
    ResourceDataSet.CalendarExceptionsDataTable calendarExceptionsDT = resClient.ReadResources(String.Empty,false).CalendarExceptions;
    
    ResourceDataSet.ResourcesRow resRow = resClient.ReadResources(String.Empty, false).Resources.First(x => x.RES_NAME.Contains("some name"));
    
    ResourceDataSet.CalendarExceptionsRow calExcRow = calendarExceptionsDT.AddCalendarExceptionsRow(resRow, "custom vacation", DateTime.Now, DateTime.Now.AddDays(2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    
    calExcRow.AcceptChanges();
    

    Last row is not working.


    Nik

    Thursday, September 13, 2012 7:36 AM
  • Hi Nik--

    Please see a sample code:

    static void AddExceptionToResourceCalender()
            {
    
               Guid ResUid = new Guid("26589954-f4c7-4368-88a0-81e783153d85");
                // //Update Resource data
    
                ResourceSvc.ResourceDataSet rds = new ResourceSvc.ResourceDataSet();
                ResourceSvc.Resource res = new ResourceSvc.Resource();
                res.UseDefaultCredentials = true;
    
                ResourceSvc.ResourceDataSet resourceDs = new ResourceSvc.ResourceDataSet();
                resourceDs = res.ReadResource(ResUid);
                res.CheckOutResources(new Guid[] { ResUid });
                ResourceSvc.ResourceDataSet.CalendarExceptionsRow cer = resourceDs.CalendarExceptions.NewCalendarExceptionsRow();
    
                cer.Name = "Sick";
                cer.RES_UID = ResUid;
                cer.Start = DateTime.Now.AddDays(3);
                cer.Finish = DateTime.Now.AddDays(3);
                cer.RecurrenceType = 0;
                cer.RecurrenceFrequency = 1;
    
                resourceDs.CalendarExceptions.Rows.Add(cer);
                
                res.UpdateResources(resourceDs, false, true);
             
    }

    It works for me without any issue.

    Thanks,


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 8:41 AM
  • Hi Amit!

    I tried that:

      • Create ResourceClient object;
      • Read all resources and get CalendarExceptions data table;
      • Put new CalendarException row into CalendarException data table;

    And i don't understand how to update or save this changes.

    Code sample:

    ResourceClient resClient;
    CreateEndpoints(out resClient);
    
    ResourceDataSet.CalendarExceptionsDataTable calendarExceptionsDT = resClient.ReadResources(String.Empty,false).CalendarExceptions;
    
    ResourceDataSet.ResourcesRow resRow = resClient.ReadResources(String.Empty, false).Resources.First(x => x.RES_NAME.Contains("some name"));
    
    ResourceDataSet.CalendarExceptionsRow calExcRow = calendarExceptionsDT.AddCalendarExceptionsRow(resRow, "custom vacation", DateTime.Now, DateTime.Now.AddDays(2), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    
    calExcRow.AcceptChanges();

    Last row is not working.


    Nik

    ResourceDataSet. CalendarExceptions.Rows.Add(calExcRow);
    resClient.UpdateResource(
    ResourceDataSet, false, true);
    Does that help?




    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 8:49 AM
  • I tried that:

    ResourceDataSet resDS = resClient.ReadResources(String.Empty, false);
    
    ResourceDataSet.ResourcesRow resRow = resClient.ReadResources(String.Empty, false).Resources.First(x => x.RES_NAME.Contains("Name"));
    
    ResourceDataSet.CalendarExceptionsRow cer = resDS.CalendarExceptions.NewCalendarExceptionsRow();
    
    cer.Name = "Sick";
    cer.RES_UID = resRow.RES_UID;
    cer.Start = DateTime.Now.AddDays(2);
    cer.Finish = DateTime.Now.AddDays(3);
    cer.RecurrenceType = 0;
    cer.RecurrenceFrequency = 1;
    
    resDS.CalendarExceptions.Rows.Add(cer);
    
    resClient.UpdateResources(resDS, false, true);

    And i have an error.

    Exception.message:

    ProjectServerError(s) LastError=CICONotCheckedOut Instructions: Pass this into PSClientError constructor to access all error information

    Exception.StackTrace:

    Server stack trace:

       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at SvcResource.Resource.UpdateResources(ResourceDataSet rds, Boolean validateOnly, Boolean autoCheckIn)
       at SvcResource.ResourceClient.UpdateResources(ResourceDataSet rds, Boolean validateOnly, Boolean autoCheckIn) in C:\Users\inm\Documents\Visual Studio 2010\Projects\ERuleCL\ERuleCL\wcf\wcf.Resource.cs:line 15204
       at ConsoleChangeVacation.Program.Main(String[] args) in C:\Users\inm\Documents\Visual Studio 2010\Projects\ConsoleChangeVacation\ConsoleChangeVacation\Program.cs:line 46

    Line 46 is:

    resClient.UpdateResources(resDS, false, true);

    Nik


    Thursday, September 13, 2012 9:51 AM
  • It was necessary to check out resource!

    After i checked out resource all is working: 

    ResourceDataSet.ResourcesRow resRow = resClient.ReadResources(String.Empty, true).Resources.First(x => x.RES_NAME.Contains("Name"));
    Thanks!


    Nik


    Thursday, September 13, 2012 9:59 AM
  • Great!! That's why I provided the sample having

    res.CheckOutResources(new Guid[] { ResUid });

    so that you can compare both.

    You may mark the thread as "Mark as answer" if smaple was good to resolve your issue.

    Thanks,


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 10:02 AM
  • Sorry, but it's not all, i need to update and delete some calendarException row.
    How i can do that?

    I found the row and would like to remove it:

    ResourceDataSet.CalendarExceptionsRow cer = resDS.CalendarExceptions.First(x => x.RES_UID == resRow.RES_UID);
    
    resDS.CalendarExceptions.RemoveCalendarExceptionsRow(cer);
    
    resClient.UpdateResources(resDS, false, true);
    

    And is not working.


    Nik

    Thursday, September 13, 2012 11:13 AM
  • Sorry, but it's not all, i need to update and delete some calendarException row.
    How i can do that?

    I found the row and would like to remove it:

    ResourceDataSet.CalendarExceptionsRow cer = resDS.CalendarExceptions.First(x => x.RES_UID == resRow.RES_UID);
    
    resDS.CalendarExceptions.RemoveCalendarExceptionsRow(cer);
    
    resClient.UpdateResources(resDS, false, true);

    And is not working.


    Nik

    Updatng resource calendar exceptions is also not possible using PSI (see http://social.technet.microsoft.com/Forums/en-US/project2010custprog/thread/078b7e12-4b33-4bb7-bcc7-ff732b96158a)

    You would have to use client side coding to set the work week for a resource calendar.

    Though you can create an exception in Res Cal but editing (Update/delete) is not possible using PSI.  http://msdn.microsoft.com/en-us/library/office/ee767706.aspx

    Defining or editing local base calendars or resource calendars, including calendar exceptions.


    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”. Thanks, Amit Khare |EPM Consultant| Blog: http://amitkhare82.blogspot.com http://www.linkedin.com/in/amitkhare82

    Thursday, September 13, 2012 1:12 PM