Using JavaScript need to Sort subsite site collection based on date in descending order

Hi,
Below is my code, where i need to sort the " webCollection
= web.getSubwebsForCurrentUser(null)" web collection based on the web.get_created() in
descending order. How could i do it any suggestions. Also i need it in JavaScript.
<script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/SP.js"></script>
<script type="text/javascript">
var context = SP.ClientContext.get_current();
var web = context.get_web();
ExecuteOrDelayUntilScriptLoaded(getWebProperties, "sp.js");
    function getWebProperties() {
                webCollection = web.getSubwebsForCurrentUser(null);
        context.load(webCollection)
        //ctx.load(this.web);
        context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
            Function.createDelegate(this, this.onFail));
    function onSuccess(sender, args) {
        //alert('web title:' + this.web.get_title() + '\n ID:' + this.web.get_id()
+ '\n Created Date:' + this.web.get_created());
        alert("Number of sites: " + webCollection.get_count());
               var webEnumerator = webCollection.getEnumerator();
                while (webEnumerator.moveNext()){
   var web = webEnumerator.get_current();
  alert("Title="+web.get_title() +"\n"+ "Created="+web.get_created());
    function onFail(sender, args) {
        alert('failed to get list. Error:'+args.get_message());
//getWebProperties();
</script>
Thanks!
MCTS- Please vote and mark posts as answered where appropriate.

Hi,
According to your post, my understanding is that you wanted to sort the subsite based on the date in descending order.
You can refer to the following code snippets, it sorts the subsites by the date in descending order.
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
// When the body is loaded, the onload event handler executes each function whose name is contained in this array.
_spBodyOnLoadFunctionNames.push("callCSOM");
function callCSOM()
$("#Button1").click(function()
ExecuteOrDelayUntilScriptLoaded(RetriveSites, "sp.js");
var currentcontext = null;
var currentweb = null;
function RetriveSites()
currentcontext = new SP.ClientContext.get_current();
currentweb = currentcontext.get_web();
this.subsites = currentweb.get_webs();
currentcontext.load(this.subsites);
currentcontext.executeQueryAsync(Function.createDelegate(this, this.ExecuteOnSuccess),
Function.createDelegate(this, this.ExecuteOnFailure));
function ExecuteOnSuccess(sender, args)
var subsites = '';
var enum1 = this.subsites.getEnumerator();
var siteCreatedTime = '';
var array=new Array();
while (enum1.moveNext())
var site = enum1.get_current();
array.push(new Array(site.get_created(),site.get_title()));
alert(array);
array=sortMethod(array);
alert(array);
function sortMethod(arr) {
var i, j, stop, len = arr.length;
for (i=0; i<len; i=i+1)
for (j=1;j<len - i; j++)
// change the "<" to ">" would be sort by the Ascending.
if (new Date(arr[j-1][0]) < new Date(arr[j][0]))
//swap(j, j+1);
var temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
//alert(new Date(arr[j]));
return arr;
function ExecuteOnFailure(sender, args) {
alert("error");
</script>
<input id="Button1" type="button" value="Run Code"/>
Results:
Sort before:
Sort after:
Thanks,
Jason
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected].
Jason Guo
TechNet Community Support

Similar Messages

  • The Specified name is already in use while activating Publishing feature at site collection level in Moss2007

    Hi,
    Please suggest on this "The Specified name is already in use while activating Publishing feature at site collection level in Moss2007"
    The specified name is already in use.
    A list, survey, discussion board, or document library cannot have the same name as another list, survey, discussion board, or document library in this Web site.  Use your browser's Back button, and type a new name.   at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateList(String
    bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt)
       at Microsoft.SharePoint.Library.SPRequest.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt)  

    there are some OutBox list/libraries being created when you activate publishing features, make sure those names not being used: check this post for more detail..
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/f7e93d26-c2a1-42c2-b191-dc48f734684b/the-specified-name-is-already-in-use-error?forum=sharepointgenerallegacy
    Please remember to mark your question as answered &Vote helpful,if this solves/helps your problem. ****************************************************************************************** Thanks -WS MCITP(SharePoint 2010, 2013) Blog: http://wscheema.com/blog

  • Help needed on Host Named Site Collection creation --- please help

    Hi Friends,
    Question 1
    Can we create Host Named Site Collection following the pattern below?
    We will have three Department head Host Named Site Collections, names –
    HRHead.ourdomain.com
    MarkettingHead.ourdomain.com
    AdminHead.ourdomain.com
    Under each of these department head sites, there will be 3 or 4 Host Named Site Collections. The site structure will be like:
    HRHead.ourdomain.com

    HR1.ourdomain.com

    HR2.ourdomain.com

    HR3.ourdomain.com
    MarkettingHead.ourdomain.com

    MarkettingProduct1.ourdomain.com

    MarkettingProduct2.ourdomain.com
    AdminHead.ourdomain.com

    AdminCountry1.ourdomain.com

    AdminCountry2.ourdomain.com

    AdminCountry3.ourdomain.com
    Question 2
    If we want to use common template (like header, footer, company icons) for inner sites (e.g. AdminCountry1.ourdomain.com, AdminCountry2.ourdomain.com, AdminCountry3.ourdomain.com) how to create that template for Host Named Site Collection? If these were
    sub sites, we can take help of site templates. But these are Host Named Site Collections, how to use common design for Host Named Site Collection?
    Any hint from you will be really helpful. Thanks for your comments.

    Yes you should be able to create a site collection using a custom template.  Here's a BLOG on how to create a site collection with a custom template in 2010.  It should still work the same way.
    http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=218
    Paul Stork SharePoint Server MVP
    Principal Architect: Blue Chip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Using DW CS6; when uploading a site DW changes all dates to today; how can I upload without changing the file-dates?

    Using DW CS6; when uploading a site DW changes all dates to today;
    how can I upload the site whilst preserving existing file-dates?
    Thanks
    Paul

    How are you uploading?
    I do not see this behavior in DWCS4 or DWCC (I assume nothing changed in DWCS6 and then back for DWCC, but I could be wrong).
    However, when I upload, I only select the files I have modified after an initial "Upload Entire Site? Yes/No" prompt. If you aren't selecting specific files to upload, and you're overwriting the files on your server with new copies of your entire local site each time, the mod dates would show as the date/time of your upload.
    To select only the files that have changed since your last upload...
    1. Right click on your local root folder in the Files window under Local View
    2. Go to Select > Newer Local from the context menu
    3. Wait until DW is done talking to the server, it could take a while, when it's done, all of the files that have a newer mod date locally than their server counterparts will be selected
    4. Click the Put (up arrow) button
    For me, this process never changes the dates of files that aren't part of the upload.

  • How to sort data in descending order when user clicks on the column heading

    Hi
    I have a report called "Top customers", which shows the top customers for a specific product line. It displays the customer name and one column with the total amount spent in the period for each product line. By default, the leftmost product line is sorted in descending order.
    If the user wants to know who are the top customers for another product line, they simply click on the column heading to sort the list by that column.
    The problem is that when you click for the first time on a sortable column heading, Apex sorts it in ascending order; you need to click on the same column heading again to sort in descending order.
    Is it possible to change this behaviour and sort the data in descending order in the first click? So the users don't have to click twice...
    Thanks
    Luis
    PS: Apex 3 running on Oracle 10.2.0

    Luis,
    See: Can I "catch" a click on a sortable column header of a report?
    Take a look at Anton Nielsen's answer with regards to hiding a column and displaying its value instead of the sortable column.
    Asumming the following simple report query:
    select product,sales
    from <table>
    Change that into:
    select product
    ,sales*-1 as reverse_sales -- Select this one as an extra column
    ,sales -- Hide this column
    from <table>
    In your report column attributes (of column reverse_sales), html-expression, type #sales#. It then displays the normal sales. However apex will generate a 'order by 2 asc' for the first time. The '2' will refer to the sales*-1 value: sorting it asc, is the same as sorting sales descending...
    Toon

  • How can I re-use an InfoPath form in several site collections?

    I have built an InfoPath 2013 form and published it to a SharePoint site. I want to use the same form, but publish it to various other site collections. I do not need the lists to interact with each other, but I would like to save the time of re-creating
    the same form over and over with the only difference being where they're published to. I attempted to change the main data connection of the form, but the modify button is greyed out. Is there a way to do this?

    Hi,
    If you want to publish one InfoPath form template for multiple site collections, you can publish it as Administrator-approved form template, then you can manage this template form from Central Administration site, and thenactivate it in required site
    collections as site collection feature.
    For more information you can see the following posts.
    http://office.microsoft.com/en-001/infopath-help/publish-a-form-HA101783381.aspx#_Toc262226390
    http://www.infopathdev.com/blogs/janice/archive/2009/03/03/administrator-approved-form-templates.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • Update a file from WSP in several site collection based on my SiteDefinition

    Hi,
    i have a minimalisitic SiteDefinition with a Stapling Feature. The Stapling Feature includes one site-scoped and another web-scoped feature. Within the Site-Scoped Feature i am deploying tweo pages.
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Module Name="MyBoxModule">
    <File Path="MyBoxModule\default.aspx" Url="default.aspx" Type="Ghostable" IgnoreIfAlreadyExists="FALSE" />
    <File Path="MyBoxModule\hilfe.aspx" Url="hilfe.aspx" Type="Ghostable" IgnoreIfAlreadyExists="FALSE" />
    </Module>
    </Elements>
    My question:
    I need to update these files each time my definition changes and the solution gets updated. For example after 2-3 month the customer wants to change the contents of the default.aspx but has created > 100 SiteCollections based on my SiteDefinition. Manually
    changing it would be a huge time expensive job. How can i build the pages in some way, that i change the pages in my solution and provide a update so that automatically after upadting the WSP the default.aspx and the hilfe.aspx are "overwritten or
    gets updated" by the file in inside the new solution.
    Best Regards
    Bog
    Developers Field Notes | www.bog1.de

    Hi,
    If you have a requirement to change a page which exists in many sites in a batch, you can use PowerShell to iterate through multiple sites and replace the original page with
    a new one in one execution.
    Iterate through site collections using PowerShell
    http://technet.microsoft.com/en-us/library/ff607950.aspx
    http://sharepoint-r3dinfo.blogspot.com/2013/08/powershell-script-to-iterate-through.html
    Use PowerShell to Upload a New File Version to SharePoint
    http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/28/weekend-scripter-use-powershell-to-upload-a-sharepoint-file-version.aspx
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • Need help creating a device collection based on members of a user collection

    Hello everyone,
        I am working on developing a device collection based on the membership of a user collection. The purpose of the device collection is to provide us with the capability of deploying software to users while the users are logged off their systems.
    I would love to use AD security groups but unfortunately that isn't an available approach in this case. I have been experimenting with SQL queries to find the best way to obtain the results I want and the following query works like a champ:
    Select SYS.Name0,
    v_R_User.Unique_User_Name0
    FROM v_R_System AS SYS
    JOIN v_UserMachineRelationship ON SYS.Name0=v_UserMachineRelationship.MachineResourceName
    JOIN v_R_User ON v_UserMachineRelationship.UniqueUserName=v_R_User.Unique_User_Name0
    JOIN v_FullCollectionMembership AS FCM on FCM.ResourceID = v_R_User.ResourceID
    JOIN v_Collection AS COLMEM ON COLMEM.CollectionID = FCM.CollectionID
    Where FCM.CollectionID = 'cha0000B'
    The problem arises when I attempt this same query in SCCM 2012, I don't get any results from this query so of course it won't work to base a Device Collection from. Here is the WQL:
    Select SYS.Name,
    SMS_R_User.UniqueUserName
    FROM SMS_R_System AS SYS
    JOIN SMS_UserMachineRelationship ON SYS.Name=SMS_UserMachineRelationship.MachineResourceName
    JOIN SMS_R_User ON SMS_UserMachineRelationship.UniqueUserName=SMS_R_User.UniqueUserName
    join sms_v_FullCollectionMembership AS FCM on FCM.ResourceID = SMS_R_User.ResourceID
    join SMS_v_Collection AS COLMEM ON COLMEM.CollectionID = FCM.CollectionIDwhere FCM.CollectionID = 'cha0000B'
    I am hoping that someone will be able to look at my SQL and tell me how I can get the WQL right so I can use this query properly or provide suggestions to accomplish what I need.
    Thanks in advance for the assist,
    Chris Bolton

    Hi Torsten,
         While your suggestion of that link was close, it still went in the direction of using security groups as the basis for device queries and that isn't the direction I am pursuing. I had a colleague look at my original query and he identified
    that I had some unnecessary redundancy but that didn't resolve my SQL -> WQL inconsistency. I continued to play with the query and the following SQL also works (and actually works a bit better for my purposes)
    select distinct v_R_System.Name0,
    v_R_User.Unique_User_Name0
    FROM v_R_System
    JOIN v_R_User on v_R_User.Full_User_Name0 = v_R_System.User_Name0
    JOIN v_UserMachineRelationship ON v_R_System.Name0 = v_UserMachineRelationship.MachineResourceName
    JOIN v_FullCollectionMembership on v_R_User.Unique_User_Name0 = v_FullCollectionMembership.SMSID
    WHERE v_FullCollectionMembership.CollectionID = 'cha0000b'
    however when I translate it to WQL I still am unable to get results (here is the WQL version)
    select distinct sms_R_system.Name,
    sms_R_User.UniqueUserName
    FROM sms_R_system
    JOIN SMS_R_User on SMS_R_User.FullUserName = SMS_R_System.UserName
    JOIN SMS_UserMachineRelationship ON SMS_R_System.Name = SMS_UserMachineRelationship.MachineResourceName
    JOIN SMS_FullCollectionMembership on SMS_R_User.UniqueUserName = SMS_FullCollectionMembership.SMSID
    WHERE SMS_FullCollectionMembership.CollectionID = 'cha0000b'
    I think I am on the verge of getting this right but it sure seems to be a challenge. Is there a "WQL Workbench" that I could use that is similar to SQL Management Studio inside of which I could test these queries rather than having to use the rather clunky
    SCCM "Edit Query Statement" dialog box?
    Thanks again,
    Chris Bolton

  • Sort records in a csv file in the descending order of time created attribute

    I have an excel (.csv) file with the following column headers :-
    Client, 
    SourceNetworkAddress
    ,TimeCreated,
     LogonType
    ,User,
    Message
    Values like :- ABC, 10.5.22.27, 11/23/2014 9:02:21 PM, 10, testuser
    The file is a combination of a report generated everyday using multiple scripts. The data is appended each day therefore, I would like to sort the final output file in descending order of time created (a combination of date and time) fetched from events
    i.e. the latest record with the latest date and time should be at the top of the list.
    I tried using the following command however, I get a sorted list according to the date but not the time. The command does not consider the AM/PM mentioned in the time instead simply sorts them as per numbers 
    Import-Csv "C:\Users\a\Desktop\report.csv" | sort Timecreated -Descending | Export-csv "C:\Users\a\Desktop\report_sorted.csv" -force -NoTypeInformation
    So if I have a record with 9:02:21 PM(latest) and a record with time 10.44.10 AM on the same date, the command will sort the list with record 10:44:10 AM first and then record with 9:02:21 PM however it should be the opposite as per descending order.
    Kindly help !!

    Hi jrv,
    Thanks for your response. However, I get errors while I run this command in Powershell :-
    Import-Csv <file> | Select Client,SourceNetworkAddress,LogonType,User,Message,@{N='TimeCreated';E={[datetime]($_.TimeCreated)} | Sort TimeCreated -Descending | Export-csv <file> -force -NoTypeInformation
    Missing expression after ','.
    At line:1 char:150
    Unexpected token 'LogonType' in expression or statement.
    At line:1 char:151
    Unexpected token ',' in expression or statement.
    At line:1 char:160
    Unexpected token 'User' in expression or statement.
    At line:1 char:161
    Unexpected token ',' in expression or statement.
    At line:1 char:165
    Unexpected token 'Message' in expression or statement.
    At line:1 char:166
    The hash literal was incomplete.
    At line:1 char:174
    Please help!
    You are missing a second curly brace - 
    Import-Csv <file> | Select Client,SourceNetworkAddress,LogonType,User,Message,@{N='TimeCreated';E={[datetime]($_.TimeCreated)}} | Sort TimeCreated -Descending | Export-csv <file> -force -NoTypeInformation

  • Using JavaScript need to clear speach bubble error messages

    Hi,
    I used AdfPage.PAGE.clearMessages(null); in javascript to clear the error message, But it will not clearing the error message(speach bubble error message), it will clearing only when ADF popup Error Messages.
    Example:
    I entered wrong date in the DateField, it shows speach bubble error message "Wrong Date Format -- Enter correct format".
    Using accessKey, I am resetting (Ctrl + t) the page. It is not resetting the page.
    If the error message is in popup, then it clearing the error message as well as resetting.
    Can anyone helpme to provide solution to clear the speach bubble error message in javascript.
    Thanks in Advance

    Hi,
    Can you explain me how to clear using field focus listener instead of a key combination for inputDate combnation.
    Thanks

  • Sorting the table records based on date (stored as string in the database)

    Iam storing the date as string(varchar2) in the database.
    Date format: DD-MMM-YYYY hh:mm:ss am/pm
    example: 12-MAY-1984 11:12:45 AM
    now i have to sort the records in such a way that recent records should be displayed first, then past records.
    i need help reagrding

    Step one: Select from the table
    Step two: Convert the string to a date
    Step three. Order on this converted date descending (= recenct records first)

  • Is it possible to sort photos by date in descending order?

    In the new Yosemite Photos app my photos are displayed in ascending order by date. The oldest photos are at the top and I must scroll all the way down to view the newest photos. In iPhoto I was able to change the sorting order so that the newest photos were always at the top. Is there a way to do this in the Photos app?

    No, sorry, that sort option is still missing.
    You may want to write feedback to Apple, to request this feature:
    Apple - Mac OS X - Feedback

  • How do you sort a text field with numeric data in numeric order

    We have a text field (varchar2) that has numeric data. When we sort it the items display as
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    *101*
    12
    Instead of
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    12
    101
    How can I make it display in numeric order if the field is a varchar2
    Howard

    To avoid string-to-number conversion:
    SQL> with t as (
      2  select '1' a from dual union
      3  select '2' a from dual union
      4  select '3' a from dual union
      5  select '4' a from dual union
      6  select '5' a from dual union
      7  select '6' a from dual union
      8  select '7' a from dual union
      9  select '8' a from dual union
    10  select '9' a from dual union
    11  select '10' a from dual union
    12  select '101' a from dual union
    13  select '12' a from dual)
    14  select a from t
    15  order by length(a), a;
    A
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    12
    101
    12 rows selected.Max
    http://oracleitalia.wordpress.com

  • Best Practice Site Collection vs SubSite

    Anyone can give me best practice on create site collection vs subsite? I generally have request for create site ,but struggle to deal with what is best. here what I have so far
    projects.contoso.com (web app and top level site collection)
    teams.contoso.com (web app and top level site collection)
    now let say I have user request for create a project site (project) that have unique security. I can take two route
    1) create a separate site collection -  projects.contoso.com/sites/projectX
    or
    2) create subsite -  projects.contoso.com/projectX (I have to break inherited here since it need it own group or individual user)
    I see both problem as I have more request and more request.
    Note: there are no other specific requirement like (specific feature, backup, sensitive data...)
    Any Thought?

    In my opinion, you create a sub-site when at least one of the groups of the root site can have access to the new sub-site.
    Otherwise, you should create a separate site collection. Every site in a site collection can see or use all the groups created in that site collection so it's very confusing and disorganized to have sites with no common security in the
    same site collection.
    And yes you might regret your decisions sometimes but it's impossible to know how a site will evolve.
    Don’t forget that by using multiple site collections:
    You won’t have a common navigation
    You cannot share site columns + content types unless you use a content type hub
    You cannot share list templates, site templates
    The content query web part is not working within multiple site collections
    It’s not possible to copy / cut/ paste using Content and structure from one site collection to another
    Usage report? (I would have to verify in SharePoint 2013)
    You can add a space quota to each site collection
    Each site collection can have different features
    Each site collection can be associated to one content database
    Hope it helps.

  • Create site Collection from site template containing blog subsite sp2013

    Hello,
    I want to create a site collection based on a `site template` that contains a `calendar app` and a `blog` subsite.
    I explain, i have a site that contains a subsite of type `blog` site and also contains a calendar in `sharepoint 2013`, i saved the site as a template and checked **`include content`**.
    However,
    when i create a new sitecollection based on that template, i get the caledar app but never the blog subsite...
    Am i missing something here? And how can we do this please?
    Thanks in advance

    Save site as Site Template only saves the individual site and its content, not the sub sites. please check below thread :
    http://social.msdn.microsoft.com/Forums/en-US/f167d3ac-afd4-407c-8108-2ae896d52752/how-to-save-site-template-with-subsites?forum=sharepointgeneralprevious
    get2pallav
    Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you.

Maybe you are looking for