none
In O365, How to create a cusom site template with one custom list based on another using Csom/Jsom ?. RRS feed

  • Question

  • In O365, How to create a cusom site template with one custom list based on another using Csom/Jsom ?. 

    As per my requirement, if i create a new site in O365, automatically one webpart/list is created in newly created site.I have this functionality available in SP2010.but in O365 no idea how can implement?

    Let me know how this should be possible in O365?provide the steps/code?

    Monday, November 20, 2017 10:45 AM

All replies

  • Hi sudhir,

    You could create a add in and then create site with custom site template with Rest API:

    function createSite() {
    var requestURL = appweburl + "/_api/SP.AppContextSite(@target)/web/webinfos/Add?@target='" + hostweburl + "'";
    var siteTitle = $('#siteTitle').val();
    var siteUrl = $('#siteTitle').val().replace(" ", "");
    var templateID = $("#ddlTemplate").val().split('#')[0];
    var jsonData = "{ 'parameters': { '__metadata': { 'type': 'SP.WebInfoCreationInformation' }, 'Title': '" + siteTitle + "', 'Url': '" + siteUrl + "', 'WebTemplate': '" + templateID + "'} }";
    
    $.ajax({
    url: requestURL,
    type: "POST",
    data: jsonData,
    headers: {
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $('#__REQUESTDIGEST').val()
    },
    success: function () { alert("site Created"); },
    error: function (xhr, status, error) {
    alert(JSON.stringify(xhr));
    }
    });
    }

    More information:

    Create New Site from Custom Web Template in Office 365 (SharePoint Online)

    Thanks

    Best Regards

     

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, November 21, 2017 9:01 AM