none
Creating Views for a SharePoint list.

    Dotaz

  • Hey,

    I have created several sharepoint lists, and I'm creating custom views for these lists.  The odd thing is, the code works fine for one list, but the same identical code will not do anything for the next list.  Here is the code I'm working with (kind of long):

    SPSite site = properties.Feature.Parent as SPSite;
                SPWeb web = site.OpenWeb();
    
                //Getting the Case Management lists.
                SPList cmCaseInformation = web.Lists["CM Case Information"];
                SPList cmSiteCreationDetails = web.Lists["CM Site Creation Details"];
    
                //Creating the Create Case View for CM Case Information view.
                SPView createCaseView = cmCaseInformation.DefaultView.Clone("Create Case View", 30, true, false);
                createCaseView.DefaultView = false;
                createCaseView.MobileDefaultView = false;
                createCaseView.MobileView = true;
                createCaseView.ViewFields.Add("Attachments");
                createCaseView.ViewFields.Add("DueDate");
                createCaseView.ViewFields.Add("ECFAcquisitionType");
                createCaseView.ViewFields.Add("ECFBranch");
                createCaseView.ViewFields.Add("ECFCertifiedValue");
                createCaseView.ViewFields.Add("ECFContractAction");
                createCaseView.ViewFields.Add("ECFContractNumber");
                createCaseView.ViewFields.Add("ECFContractType");
                createCaseView.ViewFields.Add("ECFEstimatedValue");
                createCaseView.ViewFields.Add("ECFPurchaseRequestNumbers");
                createCaseView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                createCaseView.ViewFields.Add("ECFSection");
                createCaseView.ViewFields.Add("ECFSolicitationNumbers");
                createCaseView.ViewFields.Add("ECFOffice");
                createCaseView.ViewFields.Delete("AssignedTo");
                createCaseView.ViewFields.Delete("CMURL");
                createCaseView.Update();
    
                //Creating the Shared Fields View for CM Case Information list.
                SPView sharedFieldsView = cmCaseInformation.DefaultView.Clone("Shared Fields View", 30, true, false);
                sharedFieldsView.DefaultView = false;
                sharedFieldsView.MobileDefaultView = false;
                sharedFieldsView.MobileView = true;
                sharedFieldsView.ViewFields.Add("ECFAcquisitionType");
                sharedFieldsView.ViewFields.Add("ECFCertifiedValue");
                sharedFieldsView.ViewFields.Add("ECFContractAction");
                sharedFieldsView.ViewFields.Add("ECFContractNumber");
                sharedFieldsView.ViewFields.Add("ECFEstimatedValue");
                sharedFieldsView.ViewFields.Add("ECFPurchaseRequestNumbers");
                sharedFieldsView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                sharedFieldsView.ViewFields.Add("ECFSolicitationNumbers");
                sharedFieldsView.ViewFields.Delete("AssignedTo");
                sharedFieldsView.ViewFields.Delete("CMURL");
                sharedFieldsView.ViewFields.Delete("CMCaseManager");
                sharedFieldsView.Update();
    
                //Creating the Edit view for CM Case Information list.
                SPView editView = cmCaseInformation.DefaultView.Clone("Edit View", 30, true, false);
                editView.DefaultView = false;
                editView.MobileDefaultView = false;
                editView.MobileView = true;
                editView.ViewFields.Add("DueDate");
                editView.ViewFields.Add("ECFAcquisitionType");
                editView.ViewFields.Add("ECFCertifiedValue");
                editView.ViewFields.Add("ECFContractAction");
                editView.ViewFields.Add("ECFContractNumber");
                editView.ViewFields.Add("ECFContractType");
                editView.ViewFields.Add("ECFEstimatedValue");
                editView.ViewFields.Add("ECFPurchaseRequestNumbers");
                editView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                editView.ViewFields.Add("ECFSolicitationNumbers");
                editView.ViewFields.Delete("AssignedTo");
                editView.ViewFields.Delete("CMURL");
                editView.ViewFields.Delete("CMCaseManager");
                editView.Update();
    
                //Creating the Case Header Normal View for the CM Case Information list.
                SPView caseHeaderNormalView = cmCaseInformation.DefaultView.Clone("Case Header Normal View", 30, true, false);
                caseHeaderNormalView.DefaultView = false;
                caseHeaderNormalView.MobileDefaultView = false;
                caseHeaderNormalView.MobileView = true;
                caseHeaderNormalView.ViewFields.Delete("CMURL");
                caseHeaderNormalView.Update();
    
                //Creating the Case Header Large View for CM Case Information list.
                SPView caseHeaderLargeView = cmCaseInformation.DefaultView.Clone("Case Header Large View", 30, true, false);
                caseHeaderLargeView.DefaultView = false;
                caseHeaderLargeView.MobileDefaultView = false;
                caseHeaderLargeView.MobileView = true;
                caseHeaderLargeView.ViewFields.Delete("AssignedTo");
                caseHeaderLargeView.ViewFields.Delete("CMURL");
                caseHeaderLargeView.ViewFields.Delete("CMCaseManager");
                caseHeaderLargeView.Update();
    
                //Creating the Display View for CM Case Information list.
                SPView displayView = cmCaseInformation.DefaultView.Clone("Display View", 30, true, false);
                displayView.DefaultView = false;
                displayView.MobileDefaultView = false;
                displayView.MobileView = true;
                displayView.ViewFields.Add("DueDate");
                displayView.ViewFields.Add("ECFAcquisitionType");
                displayView.ViewFields.Add("ECFAdministrativeContractingOfficer");
                displayView.ViewFields.Add("ECFBranch");
                displayView.ViewFields.Add("ECFCAGECode");
                displayView.ViewFields.Add("CMCaseManager");
                displayView.ViewFields.Add("CMCaseStatus");
                displayView.ViewFields.Add("ECFCertifiedValue");
                displayView.ViewFields.Add("ECFContractAction");
                displayView.ViewFields.Add("ECFContractNumber");
                displayView.ViewFields.Add("ECFAcquisitionType");
                displayView.ViewFields.Add("ECFDoDAAC");
                displayView.ViewFields.Add("ECFDUNS");
                displayView.ViewFields.Add("ECFEffortTotalObligationValue");
                displayView.ViewFields.Add("ECFEstimatedValue");
                displayView.ViewFields.Add("ID");
                displayView.ViewFields.Add("ECFPayStationDoDAAC");
                displayView.ViewFields.Add("ECFPIIN");
                displayView.ViewFields.Add("ECFPurchaseRequestNumbers");
                displayView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                displayView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                displayView.ViewFields.Add("ECFSection");
                displayView.ViewFields.Add("ECFShippingInformation");
                displayView.ViewFields.Add("ECFSolicitationNumbers");
                displayView.ViewFields.Add("ECFSPIIN");
                displayView.ViewFields.Add("StartDate");
                displayView.ViewFields.Add("ECFTotalObligationValue");
                displayView.ViewFields.Delete("CMURL");
                displayView.Update();
    
                //Creating the Email Notification View for CM Case Information list.
                SPView emailNotificationView = cmCaseInformation.DefaultView.Clone("Email Notification View", 30, true, false);
                emailNotificationView.DefaultView = false;
                emailNotificationView.MobileDefaultView = false;
                emailNotificationView.MobileView = true;
                emailNotificationView.ViewFields.Add("ECFAdministrativeContractingOfficer");
                emailNotificationView.ViewFields.Delete("CMURL");
                emailNotificationView.Update();
    
                //Creating the Create Case View for CM Site Creation Details list
                SPView cmCreateCaseView = cmSiteCreationDetails.DefaultView.Clone("Create Case View", 30, true, false);
                cmCreateCaseView.DefaultView = false;
                cmCreateCaseView.MobileDefaultView = false;
                cmCreateCaseView.MobileView = true;
                cmCreateCaseView.ViewFields.Add("ECFAcquisitionType");
                cmCreateCaseView.ViewFields.Add("AssignedTo");
                cmCreateCaseView.ViewFields.Add("ECFBranch");
                cmCreateCaseView.ViewFields.Add("CMCaseManager");
                cmCreateCaseView.ViewFields.Add("ECFCertifiedValue");
                cmCreateCaseView.ViewFields.Add("ECFContractAction");
                cmCreateCaseView.ViewFields.Add("ECFContractNumber");
                cmCreateCaseView.ViewFields.Add("ECFContractType");
                cmCreateCaseView.ViewFields.Add("DueDate");
                cmCreateCaseView.ViewFields.Add("ECFEstimatedValue");
                cmCreateCaseView.ViewFields.Add("ECFPurchaseRequestNumbers");
                cmCreateCaseView.ViewFields.Add("ECFRequestingOfficeDoDAAC");
                cmCreateCaseView.ViewFields.Add("ECFSection");
                cmCreateCaseView.ViewFields.Add("ECFSolicitationNumbers");
                cmCreateCaseView.ViewFields.Add("ECFOffice");
                cmCreateCaseView.Update();
    
                //Debug
                SPView testView = cmSiteCreationDetails.DefaultView.Clone("My View", 30, true, false);
                testView.DefaultView = false;
                testView.MobileDefaultView = false;
                testView.MobileView = true;
                testView.Update();
    
                site.Close();
    This identical code works fine in other projects. It will create the "Create Case View" (SPView createCaseView) for the CM Case Information List but that's as far as it will go. This identical code (variable and list names are different of course) works perfectly with other lists, has worked perfectly in other projects, but doesn't work here. What would cause that to happen because I'm completely confused. Thanks, Shaun
    12. června 2012 21:22

Odpovědi

  • My apologies Shadow.  This situation has been rectified.  I believe the way I had my shell script designed, I wasn't catching the error so to me it looked like it was just quiting.  That was my first adventure with a shell script.  Thanks for your reply.  Shaun
    14. června 2012 19:45
  • Hello RK2002,

    I had an error in the shell script that wasn't catching the error.  The solution was fairly simple.  Thanks for your reply.  Shaun

    • Označen jako odpověď Shaun Cline 15. června 2012 13:42
    14. června 2012 19:47

Všechny reakce

  • Hey,

    Do you get an error message? What happens when you run the code?

    Regards


    I find it distasteful to beg for 'Mark as Answer' and 'Mark as helpful'. It's supposed to be about helping people, not about getting the high score.

    13. června 2012 10:22
  • Hello Shadow, no error's.  This is by far the strangest thing I've seen.  No matter what I change the code to, it reads the first line and quits.
    13. června 2012 14:25
  • just to make sure...which line breaks exactly ?

    


    Serge Luca; SharePoint MVP ; blog: http://sergeluca.wordpress.com/ ICT7 http://twitter.com/sergeluca

    13. června 2012 14:39
  • Can you put a breakpoint on the code and see exactly where it breaks? You could also wrap the code in a try/catch block and read the exception's message. It could be something as simple as your list name being wrong.
    13. června 2012 19:34
  • Hello Serge,

    It breaks at SPView createCaseView = cmCaseInformation.DefaultView.Clone("Create Case View", 30, true, false);
    Here's the thing though.  It doesn't necessarily break, it just stops reading the code.  I get no compilation or runtime errors.

    13. června 2012 20:13
  • My apologies Shadow.  This situation has been rectified.  I believe the way I had my shell script designed, I wasn't catching the error so to me it looked like it was just quiting.  That was my first adventure with a shell script.  Thanks for your reply.  Shaun
    14. června 2012 19:45
  • Hello Serge,

    I found the error.  My shell script design wasn't catching the error.  It was actually fairly simple.  It couldn't find a site column.  Thanks for you reply.  Shaun

    14. června 2012 19:46
  • Hello RK2002,

    I had an error in the shell script that wasn't catching the error.  The solution was fairly simple.  Thanks for your reply.  Shaun

    14. června 2012 19:46
  • Hello RK2002,

    I had an error in the shell script that wasn't catching the error.  The solution was fairly simple.  Thanks for your reply.  Shaun

    • Označen jako odpověď Shaun Cline 15. června 2012 13:42
    14. června 2012 19:47
  • Hey,

    Glad you got it sorted out! Also mark question as answered somewhere (Like one of your replies) So that other forum users can see it as closed.

    Cheers


    I find it distasteful to beg for 'Mark as Answer' and 'Mark as helpful'. It's supposed to be about helping people, not about getting the high score.

    14. června 2012 20:29
  • Cool man, all takend care of.  Have a good day.  Shaun
    15. června 2012 13:43