Retrieve farthest date out of multiple date attribute from different source

I have similar requirements, I need to calculate identity end date , which is going to be the farthest value out of {(attribute1, source1),{attribute 3, source 2),{attribute 3, source3)}.

example:

attribute1: 2022-05-10
attribute2: 2022-05-11
attribute3: 2022-05-12

output: 2022-05-12

could you please help me how to write complex rule or transform for this. thanks in advance

compare the date with current date and take offset. Whichever offset is highest is your output. You can google the java code for this.

Thanks Chirag Patel. do you think transform can do this job or I need to write complete java rule ?

Hello @vijay_sharma,

I believe this can be done with a transform. I have written something that you can use to build off of with static values.

        {
            "name": "Latest Date",
            "type": "static",
            "attributes": {
                "date1": {
                    "type": "static",
                    "attributes": {
                        "value": "2022-05-15"
                    }
                },
                "date2": {
                    "type": "static",
                    "attributes": {
                        "value": "2022-05-12"
                    }
                },
                "date3": {
                    "type": "static",
                    "attributes": {
                        "value": "2022-05-14"
                    }
                },
                "date1gt2": {
                    "type": "dateCompare",
                    "attributes": {
                        "firstDate": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-mm-dd",
                                "outputFormat": "ISO8601",
                                "input": "2022-05-15"
                            }
                        },
                        "secondDate": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-mm-dd",
                                "outputFormat": "ISO8601",
                                "input": "2022-05-12"
                            }
                        },
                        "operator": "gt",
                        "positiveCondition": "true",
                        "negativeCondition": "false"
                    }
                },
                "date1gt3": {
                    "type": "dateCompare",
                    "attributes": {
                        "firstDate": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-mm-dd",
                                "outputFormat": "ISO8601",
                                "input": "2022-05-15"
                            }
                        },
                        "secondDate": {
                            "type": "dateFormat",
                            "attributes": {
                                "inputFormat": "yyyy-mm-dd",
                                "outputFormat": "ISO8601",
                                "input": "2022-05-14"
                            }
                        },
                        "operator": "gt",
                        "positiveCondition": "true",
                        "negativeCondition": "false"
                    }
                },
                "value": "#if($date1gt2=='true'&&$date1gt3=='true')$date1#elseif($date1gt2=='false'&&$date1gt3=='true')$date2#{else}$date3#end"
            }
        }

You will want to replace the static input strings with the dates from your sources. Your transform will look something more like the following. Be sure to replace the <attribute#> and <source#> with your values.

{
  "name": "Latest Date",
  "type": "static",
  "attributes": {
    "date1": {
      "type": "accountAttribute",
      "attributes": {
        "attributeName": "<attribute1>",
        "sourceName": "<source1>"
      }
    },
    "date2": {
      "type": "accountAttribute",
      "attributes": {
        "attributeName": "<attribute2>",
        "sourceName": "<source2>"
      }
    },
    "date3": {
      "type": "accountAttribute",
      "attributes": {
        "attributeName": "<attribute3>",
        "sourceName": "<source3>"
      }
    },
    "date1gt2": {
      "type": "dateCompare",
      "attributes": {
        "firstDate": {
          "type": "dateFormat",
          "attributes": {
            "inputFormat": "yyyy-mm-dd",
            "outputFormat": "ISO8601",
            "input": {
              "type": "accountAttribute",
              "attributes": {
                "attributeName": "<attribute1>",
                "sourceName": "<source1>"
              }
            }
          }
        },
        "secondDate": {
          "type": "dateFormat",
          "attributes": {
            "inputFormat": "yyyy-mm-dd",
            "outputFormat": "ISO8601",
            "input": {
              "type": "accountAttribute",
              "attributes": {
                "attributeName": "<attribute2>",
                "sourceName": "<source2>"
              }
            }
          }
        },
        "operator": "gt",
        "positiveCondition": "true",
        "negativeCondition": "false"
      }
    },
    "date1gt3": {
      "type": "dateCompare",
      "attributes": {
        "firstDate": {
          "type": "dateFormat",
          "attributes": {
            "inputFormat": "yyyy-mm-dd",
            "outputFormat": "ISO8601",
            "input": {
              "type": "accountAttribute",
              "attributes": {
                "attributeName": "<attribute1>",
                "sourceName": "<source1>"
              }
            }
          }
        },
        "secondDate": {
          "type": "dateFormat",
          "attributes": {
            "inputFormat": "yyyy-mm-dd",
            "outputFormat": "ISO8601",
            "input": {
              "type": "accountAttribute",
              "attributes": {
                "attributeName": "<attribute3>",
                "sourceName": "<source3>"
              }
            }
          }
        },
        "operator": "gt",
        "positiveCondition": "true",
        "negativeCondition": "false"
      }
    },
    "value": "#if($date1gt2=='true'&&$date1gt3=='true')$date1#elseif($date1gt2=='false'&&$date1gt3=='true')$date2#{else}$date3#end"
  }
}
1 Like

Thanks very much ! this was working well. later we decided to go for complex rule for better maintenance purpose. Thanks for your help.

1 Like