Forum Discussion

Rahulsingh's avatar
Rahulsingh
New Contributor
6 years ago

Expression in mapper

how to write below expression in snaplogic

least(
IIF(ISNULL(LINEAR_PREMR_DATE),to_Date(‘01/01/4000’,‘mm/dd/yyyy’),LINEAR_PREMR_DATE),
IIF(ISNULL(GO_PREMR_DATE),to_Date(‘01/01/4000’,‘mm/dd/yyyy’),GO_PREMR_DATE),
IIF(ISNULL(VOD_PREMR_DATE),to_Date(‘01/01/4000’,‘mm/dd/yyyy’),VOD_PREMR_DATE))

9 Replies

  • del's avatar
    del
    Contributor III

    One possible option:

    [LocalDate.parse($.get('LINEAR_PREMR_DATE') || '01/01/4000'),LocalDate.parse($.get('GO_PREMR_DATE') || '01/01/4000'),LocalDate.parse($.get('VOD_PREMR_DATE') || '01/01/4000')].sort().shift()

    You may need to reformat the output.

  • Rahulsingh's avatar
    Rahulsingh
    New Contributor

    Date.parse(Date.parse(Math.min(($MAX_LINEAR_PREMR_DATE == null ? 64060588800000 : Date.parse($MAX_LINEAR_PREMR_DATE).getTime()),($MAX_GO_PREMR_DATE == null ? 64060588800000 : Date.parse($MAX_GO_PREMR_DATE).getTime()),($MAX_VOD_PREMR_DATE == null ? 64060588800000 : Date.parse($MAX_VOD_PREMR_DATE).getTime()))).toString()).toLocaleDateTimeString({“format”:“MM/dd/yyyy hh:mm:ss aa”})

    • heidi_andrew's avatar
      heidi_andrew
      Contributor

      I am having similar difficulties getting the syntax right after two months of trying. I know SQL and not Java so I am having some trouble with dates and logic expressions. Here are my date issues:

      Date.parse($DATE_ELECTED).toLocaleDateTimeString({“timeZone”:“America/New_York”, “format”:“MM-dd-yyyy”})

      Here is what i get with the DATE_ELECTED column is the given $DATE_ELECTED. The column called OUTSIDE DEADLINE is the one with the above logic. Why is it showing as a day earlier?

      |DATE_ELECTED|OUTSIDE_DEADLINE|
      |10/03/2022|10-02-2022|
      |09/21/2022|09-20-2022|
      |09/23/2022|09-22-2022|

      • del's avatar
        del
        Contributor III

        @heidi.andrew

        Using Date.parse() on a date-only value will set a datetime value to midnight UTC for that date (ex. 2022-10-03T00:00:00.000 UTC). By changing the time zone to New York time, you are effectively changing it to UTC-05:00 (or -04:00 for daylight saving time), so the date-only value will show one day earlier. If you need to keep the exact date value, then you can leave out the timeZone key/value entirely.

        Date.parse($DATE_ELECTED).toLocaleDateTimeString({"format":"MM-dd-yyyy"})

  • I am also struggling to get logic to work like this:

    $field1 in (“800”,“900”)
    $field1 not in (“800”,“900”)

    I have tried several things like using the || as “or” but really just need to make a list of items to include or exclude. Tried both MATCH and CONTAINS expressions. I have also been unable to add a target schema to my mappers. Still a beginner…maybe it just takes time to figure it out. The documentation seems to go towards Java and I am a sql person. Can I print out the documentation for a snap? I am bending your ear and I appreciate the help!