Null Check in dateCompare Transform

Hi Team,

I am trying the below dateCompare transform and it is working fine for me. However if BEGDA value is null this transform is throwing me error. Can you please help me with this?

{
    "type": "dateCompare",
    "name": "BEGDA date Check",
    "attributes": {
        "firstDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "now"
                    }
                },
                "inputFormat": "yyyy-MM-dd'T'HH:mm",
                "outputFormat": "ISO8601"
            }
        },
        "secondDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "sourceName": "SAP HR - Development 2",
                        "attributeName": "BEGDA"
                    }
                },
                "inputFormat": "yyyyMMdd",
                "outputFormat": "ISO8601"
            }
        },
        "operator": "gt",
        "positiveCondition": "true",
        "negativeCondition": "false"
    }
}

How can i perform a null check for this transform?

To handle the case when the attribute “BEGDA” is null, you can use the “nullSafe” function in the attribute configuration for “secondDate.” The “nullSafe” function allows you to specify a default value that will be used in case the attribute is null. In this case, you can set a default value representing the minimum date (e.g., “0001-01-01”) or any other appropriate value for your use case.

Here’s how you can modify the “secondDate” attribute configuration to perform a null check and provide a default value:

{
  "type": "dateFormat",
  "attributes": {
    "input": {
      "type": "nullSafe",
      "attributes": {
        "value": {
          "type": "accountAttribute",
          "attributes": {
            "sourceName": "SAP HR - Development 2",
            "attributeName": "BEGDA"
          }
        },
        "defaultValue": "0001-01-01"   // Provide a default value for BEGDA when it's null
      }
    },
    "inputFormat": "yyyyMMdd",
    "outputFormat": "ISO8601"
  }
}

With this modification, if the “BEGDA” attribute is null, it will use the default value “0001-01-01” instead, and the dateCompare transform should work without throwing an error in such cases.

Hi @dheerajk27,

I did try the same thing as you suggested, still i am getting the below error.
image

Below is the transform that i have updated and used.Please let me know if there is something wrong with this.

{
    "type": "dateCompare",
    "name": "BEGDA Greater than Check",
    "attributes": {
        "firstDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "now"
                    }
                },
                "inputFormat": "yyyy-MM-dd'T'HH:mm",
                "outputFormat": "ISO8601"
            }
        },
        "secondDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "nullSafe",
                    "attributes": {
                        "value": {
                            "type": "accountAttribute",
                            "attributes": {
                                "sourceName": "SAP HR - Development 2",
                                "attributeName": "BEGDA"
                            }
                        },
                        "defaultValue": "00010101"
                    }
                },
                "inputFormat": "yyyyMMdd",
                "outputFormat": "ISO8601"
            }
        },
        "operator": "gt",
        "positiveCondition": "true",
        "negativeCondition": "false"
    }
}

Modify the secondDate to include a firstValid transform.

"secondDate": {
    "type": "dateFormat",
    "attributes": {
        "input": {
            "type": "firstValid",
            "attributes": {
                "values": [
                {
                    "type": "accountAttribute",
                    "attributes": {
                        "sourceName": "SAP HR - Development 2",
                        "attributeName": "BEGDA"
                    }
                },
                "19000101",
                ]
            }
        }
    },
    "inputFormat": "yyyyMMdd",
    "outputFormat": "ISO8601"
    }
}
2 Likes

quick note:
default value in the firstValid is not in the format yyyyMMdd specified under "inputFormat": "yyyyMMdd"

Thanks, edited it in post above.

1 Like

Hi @sharvari,

I have tried the below transform and im still getting error.

Here is the code snippet

{
    "type": "dateCompare",
    "name": "BEGDA Check",
    "attributes": {
        "firstDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "dateMath",
                    "attributes": {
                        "expression": "now"
                    }
                },
                "inputFormat": "yyyy-MM-dd'T'HH:mm",
                "outputFormat": "ISO8601"
            }
        },
        "secondDate": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "attributes": {
                        "values": [
                            {
                                "attributes": {
                                    "sourceName": "SAP HR - Development 2",
                                    "attributeName": "BEGDA"
                                },
                                "type": "accountAttribute"
                            },
                            "20400101"
                        ]
                    },
                    "type": "firstValid"
                }
            },
            "inputFormat": "yyyyMMdd",
            "outputFormat": "ISO8601"
        },
        "operator": "gt",
        "positiveCondition": "true",
        "negativeCondition": "false"
    }
}

If you are getting null for the transform output, it is most likely because the input value to dateFormat transform is not in the inputFormat you have specified. Can you reconfirm if the value of BEGDA attribute in your source is in the format yyyyMMdd

Hi Nithesh,

I rechecked and I’m using the date format as “20230821”. Still this exception is coming up

Try this for firstDate

"firstDate": {
    "type": "dateFormat",
    "attributes": {
        "input": {
            "type": "dateMath",
            "attributes": {
                "expression": "now/m",
                "roundUp": false
            }
        },
        "inputFormat": "yyyy-MM-dd'T'HH:mm",
        "outputFormat": "ISO8601"
    }
}

Hi @sindhu_v_murthy
Were you able to resolve this issue? If so, would you please share the solution you found?
TIA

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.