none
Object reference not set to an instance of object while reading the method ReadImportTimesheetData(PeriodUid) in Project Server 2007 RRS feed

  • Question

  • We had a requirement from the end user to implement import previous timesheet functionality.

    I had written the below code, but it is showing object reference not set to an instance of object for the method ReadImportTimesheetData(PeriodUid);

    private const string SERVER_URI = "http://devepm.training/pwa";
    private const string STATUSING_WEBSERVICE = "/_vti_bin/psi/statusing.asmx";
    private ResourceVacation.StatusingWS.Statusing statWS = null;
                
    public ResourceVacation.StatusingWS.Statusing StatusingWS
    {
                get
                {
                    // If we are not connected to a Project Server, make the connection
                    if (statWS == null)
                    {
                        statWS = new ResourceVacation.StatWS.Statusing();
                        statWS.Url = SERVER_URI + STATUSING_WEBSERVICE;
                        statWS.CookieContainer = new CookieContainer();
                        statWS.Credentials = CredentialCache.DefaultCredentials;
                    }
                    return statWS;
                }
     }

    Protected void LaunchImportTimesheetClick(object sender, EventArgs e)
    {
                try
                {
                    Guid PeriodUid = new Guid("FC8064F6-1941-4965-B6EE-B4EFAFECF595");
                    ResourceVacation.StatusingWS.ImportTimesheetDataSet importTimeSheetDs = statWS.ReadImportTimesheetData(PeriodUid);
                    statWS.ImportTimesheet(new Guid("39E552D4-B149-4416-8F08-FA97A0733B67"));               
                    this.messageDelEncodedLiteral.Text = "Imported time successfully";
                }
                catch (Exception ex)
                {
                }            

    Can someone guide me to overcome this error.

    Thanks,

    Vivek

    Wednesday, October 12, 2011 7:30 PM

All replies

  • Hi Vivek,

    Please verify that:

    • A Period exists with that UID
    • statWS is correctly initialized and is not null

    You might also want to review the SDK code sample for the ReadImportTimesheetData method.

    I hope this helps,
    Hans


    My EPM blog: Projectopolis
    Friday, October 14, 2011 5:47 AM
    Moderator
  • Hi Hans, Thanks now i am not getting an object reference error but i am unable to import the timesheet.Can someone help on this.
    Please find the poc code snippet below:

    const string SERVER_URI = "http://epmdev01/pwa";
    const string STATUSING_WEBSERVICE = "/_vti_bin/psi/statusing.asmx";

    ResourceVacation.StatusingWS.Statusing test = new ResourceVacation.StatusingWS.Statusing();
     test.Url = SERVER_URI + STATUSING_WEBSERVICE;
    test.CookieContainer = new CookieContainer();
    test.Credentials = CredentialCache.DefaultCredentials;

    Guid ExistingPeriodUid = new Guid("874D3E9C-9C66-4760-B9C1-A58886377D59"); // Existing period to readimporttimesheetdata
    Guid NewPeriodUid = new Guid("903eb84b-a638-4dde-9798-3dcd0450d388"); // current period to import timesheet from existing ResourceVacation.StatusingWS.ImportTimesheetDataSet importTimeSheetDs = test.ReadImportTimesheetData(ExistingPeriodUid );
    test.ImportTimesheet(NewPeriodUid ); test.SubmitStatus(null, "TimeSheet imported via Automated Process @" + DateTime.Now.ToLongDateString());
    this.messageDelEncodedLiteral.Text = "Imported time successfully";

    I am getting the sucessful message " Imported time successfully" but the tasks are not getting imported to the NewPeriod.

    Tuesday, October 18, 2011 12:58 PM
  • Hi Vivek,

    Does the timesheet for that period exist? You didn't create the timesheet in code (or checked if it existed).

    I would suggest you try the code samples for the ImportTimesheet and ReadImportTimesheetData methods and make sure they works. Once you get them running, modify them to fit your needs. That might be easier than creating your code from scratch.

    I hope this helps,
    Hans


    My EPM blog: Projectopolis
    Wednesday, October 19, 2011 5:08 AM
    Moderator