Sorting Data from an Intergation in a ReadOnly Grid

I have Data from an Integration call that is to be displayed in a ReadOnly Grid in descending order for ease of reference.

The Local Variable is structured as follows:

local!Data.result.body.contactData

contactData is an array containing ContactNumbers and each contact number's count of Sources i.e. where the number came from/ number of data providers that provided the number.

I want to sort the ReadOnly Grid such that the Initial Sort is based on Count of Sources in descending order i.e. The Contact number with the highest count of sources should be at the top.

The Sort info below logic does not work for me

a!sortInfo(
field: local!Data.result.body.contactData.numberOfSources
)

Order

Descending

Any ideas on the correct approach?

Thanks for your help in advance.

  Discussion posts and replies are publicly visible

  • field: local!Data.result.body.contactData.numberOfSources

    That's not how the "field" parameter works.  Instead you would be pasing in the field name for the column (in the context of a 2-dimensional array of data) that you want it sorted by in the resulting DataSubset, i.e. when being passed through "toDataSubset()" etc.

    How are you initially retrieving the data from the integration?  Can you pass sorting info at that point?  Are you querying ALL data at once (i.e. ignoring paging), and then just re-arranging it?

    If you could share a more complete code snippet (particularly addressing your retrieval of the data initially, then the transform you're hoping to do on it before being fed into the grid), that would be far more helpful.

  • Thanks Mike,

    The Integration returns all the Data at once no paging. I am then trying to re-arrange it. Besides the contact data there is other data that comes from the Integration therefore I cannot sort it when retrieving it.

    Summarised code snippet attached

    a!localVariables(
      local!confirm: ri!confirm,
      local!clientIdNumber: ri!client[recordIdNumber],
      local!tracingIntegrationCall: if(
        isnull(local!confirm),
        null,
        rule!LC_ConsumerTrace(
          local!clientIdNumber
          
        )
      ),
      a!sectionLayout(
            label: "Contacts",
            contents: {
              a!cardLayout(
                contents: {
                  a!gridField(
                    label: "",
                    labelPosition: "ABOVE",
                    data: local!tracingIntegrationCall.result.body.Consumer_Trace.ContactData.ContactDataRecord,
                    columns: {
                      a!gridColumn(
                        label: "Contact Number",
                        value: proper(fv!row.ContactNumber)
                      ),
                      a!gridColumn(
                        label: "Number of Sources",
                        value: proper(fv!row.numberOfSources)
                      )
                    },
                    initialSorts: {
                      a!sortInfo(
                        field: ""
                      )
                    },
                    secondarySorts: {
                      a!sortInfo(
                        field: tointeger(local!tracingIntegrationCall.result.body.Consumer_Trace.ContactData.ContactDataRecord.numberOfSources),
                        ascending: false
                      )
                    },
                    validations: {}
                  )
                },
                height: "AUTO",
                style: "TRANSPARENT",
                marginBelow: "STANDARD"
              )
            }
          )
          )

  • The "field" parameter expects a field name (or reference, if you were using RecordType data, but you're not).  Instead, you're passing it a value (or, array of values).  It may work to just use like "field: "numberOfSources"".  You would need to move that to InitialSorts as well; I don't think SecondarySorts will do much if InitialSorts is empty (though I haven't tried it).

    You'll likely have a much easier time though if you declare your DataSubset externally and then just use that for your Grid value.  That would look a little something like this:

    a!localVariables(
      local!confirm: ri!confirm,
      local!clientIdNumber: ri!client[recordIdNumber],
      local!tracingIntegrationCall: if(
        isnull(local!confirm),
        null(),
        rule!LC_ConsumerTrace(local!clientIdNumber)
      ),
      
      local!pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 10,
        sort: a!sortInfo(field: "numberOfSourecs", ascending: false())
      ),
      local!dataSubset: todatasubset(
        local!tracingIntegrationCall.result.body.Consumer_Trace.ContactData.ContactDataRecord,
        local!pagingInfo
      ),
      
      
      a!sectionLayout(
        label: "Contacts",
        contents: {
          a!cardLayout(
            contents: {
              a!gridField(
                label: "",
                labelPosition: "ABOVE",
                data: local!dataSubset,
                pagingSaveInto: local!pagingInfo,
                columns: {
                  a!gridColumn(
                    label: "Contact Number",
                    value: proper(fv!row.ContactNumber)
                  ),
                  a!gridColumn(
                    label: "Number of Sources",
                    value: proper(fv!row.numberOfSources)
                  )
                },
                /*initialSorts: {
                  a!sortInfo(
                    field: ""
                  )
                },
                secondarySorts: {
                  a!sortInfo(
                    field: tointeger(local!tracingIntegrationCall.result.body.Consumer_Trace.ContactData.ContactDataRecord.numberOfSources),
                    ascending: false
                  )
                },*/
                validations: {}
              )
            },
            height: "AUTO",
            style: "TRANSPARENT",
            marginBelow: "STANDARD"
          )
        }
      )
    )