C_Klingbeil
I'm new here

Variables Datum in ContentSelect

Jump to solution

Hallo Community,

ich versuche bei einem ContentSelect mit einem variabel gesetzten Datum zu vergleichen. Leider funktioniert das nur, wenn ich #global.now oder #startdate benutze. Folgendes rot markierte geht nicht, das grüne funktioniert:

    <CMS_FUNCTION name="define" resultname="fr_st_date">

        <CMS_CDATA_PARAM name="source">   

            <![CDATA[$CMS_TRIM(level:4)$ 

                $CMS_IF(!st_dateFrom.isEmpty && !st_dateFrom.equals(""))$

                    $CMS_SET(set_dateFrom,st_dateFrom)$

                $CMS_ELSE$

                    $CMS_SET(set_dateFrom,#startdate.getInstance())$

                    $CMS_VALUE(set_dateFrom.set(1,0,1))$

                $CMS_END_IF$ 

                $CMS_IF(!st_dateTo.isEmpty && !st_dateTo.equals(""))$

                    $CMS_SET(set_dateTo,st_dateTo)$

                $CMS_ELSE$

                   $CMS_SET(set_dateTo,#global.now)$

                $CMS_END_IF$ 

            $CMS_END_TRIM$]]> 

        </CMS_CDATA_PARAM>

    </CMS_FUNCTION>

    <CMS_FUNCTION name="contentSelect" resultname="fr_st_newsDate">

        <CMS_PARAM name="schema" value="news"/>

        <CMS_VALUE_PARAM name="from" value="set_dateFrom"/>

        <CMS_VALUE_PARAM name="to" value="set_dateTo"/>

        <QUERY entityType="news">

            <FILTERPARAM datatype="java.util.Date" parameter="from" value="-9999999990000" />

            <FILTERPARAM datatype="java.util.Date" parameter="to" value="9999999990000" />

            <AND>

                <GTE attribute="date" parameter="from"/>

                <LT attribute="date" parameter="to"/>

            </AND>

            <ORDERCRITERIA attribute="date" descending="1"/>

        </QUERY>

    </CMS_FUNCTION>   


Ich bekomme zwar für set_dateFrom wie bei #global.now einen GregorianCalendar, aber die Funktion liefert kein Ergebnis.Auch #global.now.getInstance() alleine funktioniert nicht. Hat jmd. eine Idee, warum das so ist?

Viele Grüße,

C.Klingbeil

FS4.2R4(432)

0 Kudos
1 Solution

Accepted Solutions
MarcusDau
Occasional Collector

Ich mache in einem ContentSelect folgendes:

<CMS_FUNCTION name="contentSelect" resultname="fr_win_jahr">                                                                                                          

        <CMS_PARAM name="schema" value="wasistneu"/>                                                                                                              

        <CMS_VALUE_PARAM name='von' value='#startdate.set("day_of_month",1).set("month",0).set("year",st_jahr).set("hour",0).set("minute",0).set("second",0).getTime()' /> 

        <CMS_VALUE_PARAM name='bis' value='#startdate.set("day_of_month",1).set("month",0).set("year",st_jahr+1).set("hour",0).set("minute",0).set("second",0).getTime()' />

        <QUERY entityType="eintrag">

            <ORDERCRITERIA attribute="datum" descending="1" />                                                                                                                           

            <FILTERPARAM parameter="bis" datatype="java.util.Date" value="0"/>

            <FILTERPARAM parameter="von" datatype="java.util.Date" value="0"/>                                                                                      

            <AND>                                                                                                                                             

                <GTE attribute="Datum" parameter="von" />                                                                                                       

                <LT attribute="Datum" parameter="bis" />                                                                                                       

            </AND>                                                                                                                                            

        </QUERY>                                                                                                                                                  

    </CMS_FUNCTION>


     

Hilft dir das Setzen meines bis-Datum-Parameters weiter?

Grüße

Marcus

View solution in original post

0 Kudos
2 Replies
MarcusDau
Occasional Collector

Ich mache in einem ContentSelect folgendes:

<CMS_FUNCTION name="contentSelect" resultname="fr_win_jahr">                                                                                                          

        <CMS_PARAM name="schema" value="wasistneu"/>                                                                                                              

        <CMS_VALUE_PARAM name='von' value='#startdate.set("day_of_month",1).set("month",0).set("year",st_jahr).set("hour",0).set("minute",0).set("second",0).getTime()' /> 

        <CMS_VALUE_PARAM name='bis' value='#startdate.set("day_of_month",1).set("month",0).set("year",st_jahr+1).set("hour",0).set("minute",0).set("second",0).getTime()' />

        <QUERY entityType="eintrag">

            <ORDERCRITERIA attribute="datum" descending="1" />                                                                                                                           

            <FILTERPARAM parameter="bis" datatype="java.util.Date" value="0"/>

            <FILTERPARAM parameter="von" datatype="java.util.Date" value="0"/>                                                                                      

            <AND>                                                                                                                                             

                <GTE attribute="Datum" parameter="von" />                                                                                                       

                <LT attribute="Datum" parameter="bis" />                                                                                                       

            </AND>                                                                                                                                            

        </QUERY>                                                                                                                                                  

    </CMS_FUNCTION>


     

Hilft dir das Setzen meines bis-Datum-Parameters weiter?

Grüße

Marcus

0 Kudos

Danke für den Hinweis mit dem getTime(). Das war der Fehler. Jetzt sieht die Funktion so aus:

    <CMS_FUNCTION name="define" resultname="fr_st_date">

        <CMS_CDATA_PARAM name="source">   

            <![CDATA[$CMS_TRIM(level:4)$ 

                $CMS_IF(!st_dateFrom.isEmpty && !st_dateFrom.equals(""))$

                    $CMS_SET(set_dateFrom,st_dateFrom)$

                $CMS_ELSE$

                    $CMS_SET(set_dateFrom,#startdate.set("day_of_month",1).set("month",0).set("year",1).set("hour",0).set("minute",0).set("second",0).getTime())$

                $CMS_END_IF$ 

                $CMS_IF(!st_dateTo.isEmpty && !st_dateTo.equals(""))$

                    $CMS_SET(set_dateTo,st_dateTo)$

                $CMS_ELSE$

                    $CMS_SET(set_dateTo,#global.now)$

                $CMS_END_IF$ 

            $CMS_END_TRIM$]]> 

        </CMS_CDATA_PARAM>

    </CMS_FUNCTION>

    <CMS_FUNCTION name="contentSelect" resultname="fr_st_newsDate">

        <CMS_PARAM name="schema" value="news"/>

        <CMS_VALUE_PARAM name="from" value="set_dateFrom"/>

        <CMS_VALUE_PARAM name="to" value="set_dateTo"/>

        <QUERY entityType="news">

            <FILTERPARAM datatype="java.util.Date" parameter="from" value="-9999999990000" />

            <FILTERPARAM datatype="java.util.Date" parameter="to" value="9999999990000" />

            <AND>

                <GTE attribute="date" parameter="from"/>

                <LT attribute="date" parameter="to"/>

            </AND>

            <ORDERCRITERIA attribute="date" descending="1"/>

        </QUERY>

    </CMS_FUNCTION>   

0 Kudos