How to Add a condition to return'none'

Hello Expert,

I am trying to add a condition that will return "none’’ if there is no value in lastLogon
and lastLogonTimestamp. The condition that I added doesn’t seem to work.

Here is the transform I created.

{
    "id": "",
    "name": "",
    "type": "static",
    "attributes": {
        "date1": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "firstValid",
                    "attributes": {
                        "values": [
                            {
                                "type": "accountAttribute",
                                "attributes": {
                                    "attributeName": "lastLogon",
                                    "sourceName": "Active Directory Prod"
                                }
                            },
                            {
                                "attributes": {
                                    "value": "125911584000000000"
                                },
                                "type": "static"
                            }
                        ]
                    }
                },
                "inputFormat": "EPOCH_TIME_WIN32",
                "outputFormat": "yyMMddHH"
            }
        },
        "adLastLogon": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "attributeName": "lastLogon",
                        "sourceName": "Active Directory Prod"
                    }
                },
                "inputFormat": "EPOCH_TIME_WIN32",
                "outputFormat": "yyyy-MM-dd"
            }
        },
        "date2": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "firstValid",
                    "attributes": {
                        "values": [
                            {
                                "type": "accountAttribute",
                                "attributes": {
                                    "attributeName": "lastLogonTimestamp",
                                    "sourceName": "Active Directory Prod"
                                }
                            },
                            {
                                "attributes": {
                                    "value": "125911584000000000"
                                },
                                "type": "static"
                            }
                        ]
                    }
                },
                "inputFormat": "EPOCH_TIME_WIN32",
                "outputFormat": "yyMMddHH"
            }
        },
        "adLastLogonTimestamp": {
            "type": "dateFormat",
            "attributes": {
                "input": {
                    "type": "accountAttribute",
                    "attributes": {
                        "attributeName": "lastLogonTimestamp",
                        "sourceName": "Active Directory Prod"
                    }
                },
                "inputFormat": "EPOCH_TIME_WIN32",
                "outputFormat": "yyyy-MM-dd"
            }
        },
        "value": "#set($i=0)#if(($i.parseInt($date1) gt $i.parseInt($date2)))$adLastLogon#elseif(($i.parseInt($date2) gt $i.parseInt($date1)))$adLastLogonTimestamp#elseif($date1 =='125911584000000000' && $date2 =='125911584000000000')none#{else}$adLastLogon#end"
    },
    "internal": false
}

You can use static transform and assign “none” as a constant variable and set like what you have set for other variables that you have used in your velocity code.

@kdfreeman

You mean instead of putting default value I should have “ none”.

I have tried putting “none” instead of default value. It throws error saying “ value cannot be evaluated:null”

Thank you

No. Use a variable inside your transform that can save “none” String. You can use that in your velocity code like you have used for other variables. For example, add extra variable in your transform temp.

 "temp": {
      "type": "static",
      "attributes": {
        "value": "none"
      }
    }

Now , instead of using none in your velocity code, use $temp in place of none.

Hi,

You added condition

#elseif($date1 =='125911584000000000' && $date2 =='125911584000000000')none

if in case there is no data in “lastLogonTimestamp” and “lastLogon” it wont return these values. You are converting using date format and converting it into “yyMMddHH” and “yyyy-MM-dd”.

I think you should add converted values something like “5959-12-25” in elseif condition.

Try adding this converted date into the if condition.

-Abhinov

Thank you @Abhinov7 @kdfreeman
I need to combine both of yours solution to make it work.

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