Default view connection between site collection and subsite is not complete if I use a template to generate the subsite.

emarck 2010 21 Reputation points
2022-03-09T22:31:45.6+00:00

Hi,

I have site collection who have 2 lists.

Project info

User info

Project info contain somes information about each project.

Ex: Project title, cost, years, manager, link to the subsite of the project.

The list user info contain somes information about who have access to the project.

Ex: Title of project , username, type of access (read only, modify)

The challenge was to give an easy way at the manager for manage users access for a particular project.

For that, I have create a aspx page in SPD 2013 at the site collection level.

In this blank page, I add a data view of my Project info list.

I have save the page at the site collection level and use the option in SPD 2013 to generate a custom webparts of this views in the Sharepoint toolbars.

Like this I could insert this web part in my subsite and I have direct link with site collection list Project info.

I have make the same with the other list User info.

After that, I have create a new blank subsite in my site collection.

One time in my subsite, I have create a new aspx page and add each custom webparts on it.

The result is super, I have the data from the list who are at the site collection level in my subsite.

I could change the view to add or remove somes column and I could delete or add items without any problem.

If I go at my site collection level I could view the new items create in the list from the subsite.

All work very well.

But When I go in the option of the subsite to create and save the subsite like a template, I lost the majority of column selected in the default view in the subsite.

So if I try to create a new subsite with this template, the subsite is generate, but in the info page I view my 2 webparts who are always connect to the site collection list.
But the view of this 2 webparts are scrap, I have only the title column.

If I modify the info page in the new subsite generate by the template, I could go in the properties of the webparts and all the view create at the site collection level are present.

So I could manually select in the list the rigth view I need for each webparts of the info page.

When I make this and save the page, all my fields are present correctly.

But I need to make this manually each time than I create a new subsite, I have try to put the view in th subsite by default for each webparts and generate a new template, but I have the same view problem each time.

My goal is to find a way to conserve the format of each view in the template, because I use this template in a workflow the auto generate the futur subsite.

Any hints about this problem ?

Thank you.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,607 questions
{count} votes

4 answers

Sort by: Most helpful
  1. JoyZ 18,111 Reputation points
    2022-03-11T09:23:30.667+00:00

    @emarck 2010 ,

    Thanks for the detailed screenshot steps!

    Per my test, I can reproduce your issue, however we have no workaround for this, currently we can only add columns manually in this view:

    182221-image.png


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

  2. emarck 2010 21 Reputation points
    2022-03-11T14:09:31.983+00:00

    OK , I could maybe use another method to conserve the columns or add columns in the view with rest api command ?

    Or another method to have the same result between site collection and subsite ?

    Thank you.

    0 comments No comments

  3. emarck 2010 21 Reputation points
    2022-03-11T22:07:56.84+00:00

    I have make somes research and view on somes site than I could create a view in javascript.

    I found somes script who give how :

    create a view from scratch
    delete a existing view
    list all view availaible

    But I dont find information about view selection. I suppose this is possible like somes code exist to create, list and delete views.

    Somebody have any information about that ?

    Because, if I could put a javascript who load with the page, maybe than I could resolve the issue with a script who change the webparts view for the good one each time I load the page.

    Thank you.


  4. RaytheonXie_MSFT 40,451 Reputation points Microsoft External Staff
    2022-03-14T09:33:26.317+00:00

    Hi @emarck 2010 ,
    You can follow the code to set View Query in SharePoint

    <script src="https://code.jquery.com/jquery-2.2.4.js" type="text/javascript"></script>  
    <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>  
    <script type="text/javascript" src="/_layouts/15/sp.js"></script>  
    <script src="https://MyServer/sites/SiteCollection/style library/js/ScriptFile.js"></script>  
    <script>  
    function SetListViewQuery() {  
        // You can optionally specify the Site URL here to get the context  
        // If you don't specify the URL, the method will get the context of the current site  
        // var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");  
        var clientContext = new SP.ClientContext();  
       
        // Get List Object  
        var olistCollection = clientContext.get_web().get_lists();  
        var oList = olistCollection.getByTitle("List Name");  
       
        // Get required view by specifying view Title here  
        var oView = oList.get_views().getByTitle('Custom View');  
       
        // Set the view Query.   
        oView.set_viewQuery("<Where><IsNotNull><FieldRef Name='Title'/></IsNotNull></Where>");  
       
        // Update view  
        oView.update();  
       
        // Execute the query to the server.  
        clientContext.executeQueryAsync(onsuccess, onfailed);  
    }  
       
    function onsuccess() {  
    }  
       
    function onfailed(sender, args) {  
    }  
    </script>  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.