Lifecyclestate transform using vtl

Hello Everyone,

If there four life cycle states lets say,: ‘created’,‘active’,‘dormant’ and ‘inactive’ and if a user start date is in future when compared to todays date then “created”, elseif users startdate is less than or equal to todays date and end date is greater than equal to todays date then “active”, else if users enddate is less than current date then “dormant” else if users end date is less than 30 days of todays date then “inactive”. I’ve written a transform but only ‘active’ and ‘dormant’ are working fine. Could anyone please suggest a way so that all 4 lcs states will work fine.

Thank you & kind regards
Mane


I can see why inactive is never being reached. Try switching the elseif for dormant and inactive so that dormant is last.

As for created never being reached, the only reason I can see is your test data never triggers that condition. Have you made sure that your start date is in the future when testing created?

Thanks a lot @colin_mckibben, now created is working fine but only inactive lcs is not working eventhough there is relevant test data for it. As per expectation lcs should be “inacive”. Kindly see the attached screenshot for reference. Could you please suggest one?

Thank you & kind regards
Mane

It looks like the root of your problem is how you are comparing the dates. You convert them to “ddMMyyyy”, then run a compareTo method on the string representations of the dates. The problem is that compareTo compares strings lexicographically, not numerically. This means that trying to compare two strings that are >= 30 will never work because comparing strings doesn’t produce a result like that. Dates are complicated, and simple integer or string comparison won’t tell you the number of days between two dates. That will require a more complex function.

public class Main {
  public static void main(String[] args) {
    String now = "14022023"; // February 14, 2023
    String end = "01112023"; // November 1, 2023
    System.out.println(now.compareTo(end)); // returns 1
  }
}
public class Main {
  public static void main(String[] args) {
    String now = "14022023"; // February 14, 2023
    String end = "11112023"; // November 11, 2023
    System.out.println(now.compareTo(end)); // returns 3
  }
}

You might be able to solve this use case by using date math and date compare operations. Check this post to see how you can project a date 30 days into the future and then run a comparison to see if it is simply greater or less than the current date.

Thanks a lot @colin_mckibben :slight_smile: , it worked with combination of dateCompare, dateFormat and dateMath with necessary expressions.

Thank you & kind regards
Mane

Glad to see it worked. If you don’t mind, can you please share your final solution? It will help future readers of this topic.

sure!, please see the below code:

{
    "name": "lcs",
    "type":"static",
    "attributes": {
        "inPast": {
            "type": "dateCompare",
            "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": "<>",
                                "attributeName": "<>"
                            }
                        },
                        "inputFormat": "ddMMyyyy",
                        "outputFormat": "ISO8601"
                    }
                },
                "operator": "lt",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
       
	    "start": {
            "type": "dateCompare",
            "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": "<>",
                                "attributeName": "<>"
                            }
                        },
                        "inputFormat": "ddMMyyyy",
                        "outputFormat": "ISO8601"
                    }
                },
                "operator": "gte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
	   
	   "end_date": {
            "type": "dateCompare",
            "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": "<>",
                                "attributeName": "<>"
                            }
                        },
                        "inputFormat": "ddMMyyyy",
                        "outputFormat": "ISO8601"
                    }
                },
                "operator": "lte",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },

       
	   
	   
	   
	   
	  "thirtycheck": 
       { 
	   
	   "type": "dateCompare",
            "attributes": 
			{
                "firstDate": 
				{
                    "attributes": 
					{
                        "expression": "now-30d/d",
                        "roundUp": false
                    },
                    "type": "dateMath"
                },
                "secondDate": {
                    "attributes": {
                        "input": {
                            "type": "accountAttribute",
                            "attributes": {
                                "attributeName": "<>",
                                "sourceName": "<>"
                            }
                        },
                        "inputFormat": "ddMMyyyy",
                        "outputFormat": "ISO8601"
                    },
                    "type": "dateFormat"
                },
                "operator": "gt",
                "positiveCondition": "yes",
                "negativeCondition": "no"
            }
           
         },
	   

		"d_check": {
            "type": "dateCompare",
            "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": "<>",
                                "attributeName": "<>"
                            }
                        },
                        "inputFormat": "ddMMyyyy",
                        "outputFormat": "ISO8601"
                    }
                },
                "operator": "gt",
                "positiveCondition": "true",
                "negativeCondition": "false"
            }
        },
		
        "value": "#if($inPast=='true')ABCD#elseif($start=='true' && $end_date=='true')XYZ#elseif($thirtycheck=='yes')PQRS#elseif($d_check=='true')anything#{else}#end"
    }
}