How to retrieve the current date in a jELement expresion of sequence in JS?

Home Forums Convertigo developers Forums as moved to Stack Overflow. How to retrieve the current date in a jELement expresion of sequence in JS?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #210902

    Hello,

    I want to define an expression in jELement component of a sequence to retrieve the current date.
    The sequence contains an inputVars and jElement currentDay.

    WHen I fill the expression by that: new Date().toLocaleDateString(‘en-GB’) I get the following error:

    Unable to evaluate step expression code for ‘expression’ property or variable.
    Step: “jElement”
    A Javascript runtime error has occured at line 1, column 0: TypeError: 2018-02 n’est pas une fonction, c’est un object (expression#1)

    Normally, new Date() gives to me the current date in javascript. But the result isn’t. I get 2018-02. Why?

    Regards,

    Jalal EL AMRANI
    Warren-walter

    #210903

    Gregory Vorbe
    Moderator

    Hello Jalal,

    I created a new jElement step with ‘Expression’ property set to
    new Date().toLocaleDateString("en-GB")
    When I execute the sequence i have no error and the step returns me an XML tag containing the current date (but not formatted to en-GB).
    Try to put classic simple or double quotes around your locale, the ones you gave in your example are not proper quotes.

    QA&Support

    #210904

    Gregory Vorbe
    Moderator

    Jalal,

    I suggest you to use a SequenceJS step instead of the jElement.
    It would be more comfortable to write the code with a plain text editor and you will be able to write native Java code which is more efficient to format date object.

    QA&Support

    #210913

    Gregory,

    I define a sequence with a sequenceJS step.
    I implement that code
    =getCUrrentMonthYear();

    java.lang.String getCUrrentMonthYear() {
    java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat(“MMMM yyyy”, Locale.FRENCH);
    java.lang.String dateStr = simpleDateFormat.format(new java.util.Date());
    return dateStr;
    }
    When I launch it I get that error:
    <?xml version=”1.0″ encoding=”UTF-8″?>

    <document>
    <error project=”Maprospection” sequence=”getCurrentMonthYear” type=”c8o”>
    -1
    <message>An exception occured while executing step</message>
    <details>Unable to evaluate step expression code for ‘expression’ property or variable.
    Step: “Sequence_JS”
    A Javascript evaluation error has occured: erreur de syntaxe (expression#1)</details>
    <context/>
    <exception>com.twinsoft.convertigo.engine.EngineException</exception>
    <stacktrace>com.twinsoft.convertigo.engine.EngineException: An exception occured while executing step
    at com.twinsoft.convertigo.beans.core.Step.execute(Step.java:630)
    at com.twinsoft.convertigo.beans.core.Sequence.executeNextStep(Sequence.java:1576)
    at com.twinsoft.convertigo.beans.core.Sequence.executeNextStep(Sequence.java:1294)
    at com.twinsoft.convertigo.beans.sequences.GenericSequence.runCore(GenericSequence.java:44)
    at com.twinsoft.convertigo.beans.core.RequestableObject$RequestableThread.run(RequestableObject.java:811)
    Caused by: com.twinsoft.convertigo.engine.EngineException: Unable to evaluate step expression code for ‘expression’ property or variable.
    Step: “Sequence_JS”
    A Javascript evaluation error has occured: erreur de syntaxe (expression#1)
    at com.twinsoft.convertigo.beans.core.Step.evaluate(Step.java:828)
    at com.twinsoft.convertigo.beans.steps.SimpleStep.stepExecute(SimpleStep.java:79)
    at com.twinsoft.convertigo.beans.core.Step.execute(Step.java:625)
    … 4 more
    </stacktrace>
    </error>
    </document>
    Why?

    #210915

    Gregory Vorbe
    Moderator

    Hello Jalal,

    Here is the code to write in your SequenceJS step.
    In my example, the sequence has a variable called ‘myDate’ and receive the value ‘2018/03/02’
    This is a string.

    // myDate is the sequence variable containing String "2018/03/02"
    // Transform String to Date object
    preFormatter = new java.text.SimpleDateFormat("yyyy/MM/dd");
    oDate = preFormatter.parse(myDate);
    
    formatter = new java.text.SimpleDateFormat("MMMM yyyy", java.util.Locale.FRENCH);
    myFormattedDate = formatter.format(oDate);

    QA&Support

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.