Code Generated List - Sort Column Descending By Default

SOLVED

If would be wonderful if someone could assist me with the following.  I have written an ASP page which displays a list of orders.  This list is generated in the code and does not rely on any metadata.  A snippet of the code is included below

    var list = CRM.GetBlock("list");

    var listFields = ['orde_q_documentdate', 'orde_qs_erporderreference', 'Orde_grossamt', 'Comp_Name', 'Oppo_Description'];

    //Add Fields To List

    for(var l=0; l<listFields.length; l++){

        var col = list.AddgridCol(listFields[l],-1,true);

        col.JumpEntity = "orders";

    }

The page displays the list of orders as expected, the list being ordered by the first column.  The column is ordered ascending, ideally this should be ordered descending.

 

 

When altering lists in the UI an option is available to “Order By Desc”

 

Looking at the documentation this does not appear to be an option when creating a list programmatically

CRMGridColBlock properties

  • Alignment. Sets the alignment of text within the column.
  • AllowOrderBy. Sorts entries in the list by the values in the column.
  • CustomActionFile. Hyperlinks a column to an ASP file.
  • CustomIdField. Allows a value to be passed to the custom file when the corresponding column is selected.
  • JumpEntity. Adds a hyperlink that opens the summary screen of an entity record.
  • ShowHeading. Shows or hides the column heading.
  • ShowSelectAsGif. Shows the values in the column as GIF image

 

https://help.sagecrm.com/on_premise/en/2023R1/Dev/Content/Developer/ASP%20Object%20Reference/CRMGridColBlock%20Object/AS_CRMGridColProperties.htm

 

Is there a way to order columns in descending value when the column is created programmatically?  It is possible for the end user to select the column heading to reverse the order, but to sort descending by default would give a better end user experience.

  • +1
    verified answer

    Hi Alison

    These are from my notes.  The property that we want to control is OrderByDesc.

    //GridColBlock properties
    // AllowOrderBy = true|false
    // OrderByDesc = true|false
    // CustomActionFile
    // CustomIdField
    // Alignment
    // JumpEntity
    // ShowHeading = true|false
    // ShowSelectAsGif = true|false
    // JumpAction
    // JumpKey
    // CreateScript
    // Visible = true|false

    myGridColBlock.AllowOrderBy = true;
    myGridColBlock.OrderByDesc = false;
    myGridColBlock.Alignment = "LEFT|RIGHT|CENTER";
    myGridColBlock.ShowHeading = false;
    myGridColBlock.ShowSelectAsGif = false;
    myGridColBlock.JumpEntity= "Company|Person|Communication|Case|Address|Library|Notes";

    I will get that sorted in the documentation.

    Thanks

  • 0

    Hi

    I know that this has been answered. I'm not a developer, but intrigued why design a table within an ASP page and not create a custom table within CRM and call on it in the ASP page?

  • 0 in reply to Matthew Shaw

    Hi Matthew 

    I don't know what Alison would say... but I think this is to do with asking dynamic questions when you don't necessarily know what the answer will be and how you want to display it.    I think there are two categories of use.

    Firstly, the API allows you to create a list block without reference to metadata, you can then base it on any SQL query statement you want.  That SQL query can fetch the rows and columns you want and so will then need to add those columns to the grid.

    Secondly, the API allows to adapt a meta data defined list by adding additional columns if the circumstances require it.   

  • 0 in reply to Matthew Shaw

    The main reasons why I am building a list in this way are

    1. When the asp page is deployed I don't then have to worry about creating lists and views in CRM itself, I just deploy the ASP page.
    2. The metadata is kept tidy so if the ASP page is removed in the future then I also don't have to remove the list and / or view.  In my experience the more metadata you have in a CRM implementation the less efficient CRM runs.
    3. It is often quicker when developing the ASP page to build and maintain the list in the ASP page rather then build the list in metadata and then reference it in the ASP page.
    4. Everything is kept in one place so all changes are made in the code rather then having to make changes to the code and / or metadata.
    5. Fields can be more easily added and / or removed from lists dynamically when they are fully maintained in the code

    Also when building the list in the code it means that the list cannot be edited within CRM itself.  This can be a bad thing as it reduces flexibility but it can also be a good thing as it prevents lists being altered which should not be altered.   

  • 0 in reply to AlisonA

    I would flag a warning.  Coders tend to see everything as a coding problem. 

    The design philosophy  of Sage CRM is to reduce the amount of code and where possible eliminate code.  Code has to be maintained and has to be updated and so requires coding skills.  What may be a cheap, quick and convenient way of implementing a solution may pass expense, delay and hassle to a project when it comes to upgrading or adapting a system when business needs change.

    So there.