Forum Discussion

karthik_dhina's avatar
karthik_dhina
New Contributor
3 years ago

Mapper - change value in target path based on condition

I have the below req.

i want to update the value of a column only if it’s null else leave as it is.

ex: raw_table.date_joined will be populated only if it’s null, if it’s already have a value leave it.

mapper:

expression Target


Date.Now() $date==null||Date.Now():$date

how to do this.

2 Replies

  • bojanvelevski's avatar
    bojanvelevski
    Valued Contributor

    Hi @karthik_dhina,

    You can do this by using the ternary operator. Check this out:

    $date == null ? Date.now() : $date

    This translated means, get me the ‘date’ field, but if it’s null, than get the current datetime. If you want to add current datetime even if the field doesn’t exist, than try the following:

    $.get('date') == null ? Date.now() : $date

    BR,
    Bojan

    • darshthakkar's avatar
      darshthakkar
      Valued Contributor

      @karthik_dhina: The solution has been provided by @bojanvelevski - trust me it works. If at all you do not want to use a mapper then you can always leverage some snaps like filter and router for the same but you’ll have to use a mapper after the results are filtered and assign the default value.

      Alternatively, you can also use Conditional snap to achieve similar use cases.