Nuri Ensing
Nuri Ensing

Reputation: 2030

Same field name different data types how to check if empty

In IBM notes I have a Java agent which checks if the field ActualDelivery date is empty or not:

 String ActualDeliveryDate =  orderRegelDocument.getItemValueString("ActualDeliverydate");
 if (ActualDeliveryDate.equals("")  ){

But the problem is that this field ActualDeliverydate is set in some documents as a Text field and in some documents as a DateTime field.. So how can I know when it is a text field and then take the string and when to take it as DateTime?

Upvotes: 0

Views: 90

Answers (3)

Richard Schwartz
Richard Schwartz

Reputation: 14628

Get the Item instead of the item value.

Item theItem orderRegelDocument.getFirstItem("ActualDeliverydate");

Then check the Item's Type property and do the conversion if necessary:

String ActualDeliveryDate;
if (theItem.getType() == Item.DATETIMES)
{
 DateTime dt = theItem.getDateTimeValue();
 ActualDeliveryDate = dt.getLocalTime();
}
else
{
 ActualDeliveryDate =  orderRegelDocument.getItemValueString("ActualDeliverydate");
}

Upvotes: 2

Andre Krepsky
Andre Krepsky

Reputation: 111

Aditionally, you could delete empty DateTime and Number fields from documents. In classic Notes development, a simple @If(@Text(@ThisValue) = ""; @DeleteField; @ThisValue) in InputValidation can do the job.

Upvotes: 0

J.Mengelle
J.Mengelle

Reputation: 341

I don't use IBM notes, but this should work

Object actualDeliveryDate = orderRegelDocument.getItemValue("ActualDeliverydate");
if(actualDeliveryDate instanceOf String){
    //compare with a string
}else if(actualDeliveryDate  instanceOf Date){
   //do something else
} 

I don't know about the actuel object that are used, so just debug it to see it.

Upvotes: -1

Related Questions