我们正在尝试使用以下 if-else 条件比较日期。如果我们使用常量值,则条件会正确评估。但是,当我们使用数组值的引用时,代码无法按预期工作。在此处请求您的指导。
last Execution date 你可以取今天的日期。
输入有效载荷:
<items>
<row>
<id>1</id>
<status__v>Approved</status__v>
<approved_date__c>2021-06-17</approved_date__c>
<major_version_number__v>1</major_version_number__v>
</row>
<row>
<id>2</id>
<status__v>Approved</status__v>
<approved_date__c>2021-08-30</approved_date__c>
<major_version_number__v>1</major_version_number__v>
</row>
<row>
<id>3</id>
<status__v>Approved</status__v>
<approved_date__c>2021-10-01</approved_date__c>
<major_version_number__v>1</major_version_number__v>
</row>
</items>
常规代码:
import com.sap.it.api.mapping.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.*
import java.lang.*;
import java.util.*;
def void Itemstatus(String[] ApprovedDt,String[] status,String[] version,String[] propertyName, Output output,MappingContext context)
{
String lets = context.getProperty(propertyName[0]); // "lets" will get value "2021-09-30"
SimpleDateFormat formatter1=new SimpleDateFormat("yyyy-MM-dd");
datelets=formatter1.parse(lets);
Date date = new Date();
String CurrentDate = date.format("yyyy-MM-dd"); // "currentDate" value "2021-09-30"
def status1 = ["Active","Inactive"];
for(int i=0; i<status.size(); i++)
{
dateApprovedDt = formatter1.parse(ApprovedDt[i]); // "dateApprovedDt" value "2021-06-17"
if (status == "Approved" && dateApprovedDt > datelets)
{
output.addValue(status1[0])
}
else if(status == "Approved" && dateApprovedDt > datelets && version[i] > "1") //version value "1"
{
output.addValue(status1[0])
}
else if (status == "Approved" && dateApprovedDt < CurrentDate)
{
output.addValue(status1[1])
}
else
{
output.addValue(status1[2])
}
}
}