This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Orderby quering the database with script

Hi all,

 

I need to get the reasonHead from Decisiontype Unsubscribe on a Request but if on that request are started more Unsubscribe I need to get the last one made.

Basically I need the orderby on Connection.getSingleValue or Connection.getSingleRow.

 

I tried too with a IColDbObject e SQLFormatter but can't find any documentation if this is possible

The workaround is to loop on the result of IColDbObject  and take the row with the newer date. But seems impossible that you can't do order by on a query.

 

I search for some documentation on script classes but can't find 

 

 

Thanks Mik

  • Hi Michele,

    I propose to use the new object layer methods based around session to get what you need. You can check the ScriptSamples in the SDK off the product delivery.

    For your use case, as far as I was able to understand it, the following script sample should do.

    Public Function CCC_GetSingleValueWithOrderBy(UID_PersonWantsOrg As String) As String
    Dim f As ISqlFormatter = Session.SqlFormatter

    Dim WhereClause As String = f.AndRelation(
    f.Comparison("DecisionType", "Unsubscribe", ValType.String),
    f.Comparison("UID_PersonWantsOrg", UID_PersonWantsOrg, ValType.String))

    Return Session.Source.GetSingleValue(Of String)(Query.
    From("PWODecisionHistory").
    Where(WhereClause).
    OrderBy("DateHead DESC").
    Select("ReasonHead"))
    End Function
  • Thanks Markus
    One day you should collect all these questions in a Q&A section