How to check Mapping field not have any value

Hi,
I am trying to create a new field to calculate the duration, during the creation of the field I did not find any issue or error, but while refreshing the Discover page throwing the below error.

image

Please see the below script for reference.

String completedtime= doc['readyCreatedTime'].value.toString();

if(completedtime=='-'){

long datenow = new Date().getTime();

long datewas = doc['createdTime'].value.getMillis();

long milisecondnd=datenow - datewas;

long second=milisecondnd/1000;

long hours=second/86400;

emit(hours);

}

else{

long datenow = doc['createdTime'].value.getMillis();

long datewas = doc['createdTime'].value.getMillis();

long milisecondnd=datenow - datewas;

long second=milisecondnd/1000;

long hours=second/86400;

emit(hours);

}

Sample data image

Hi @PappuSingh

Please format your code in the future ... you have to check if the field exists you can not get the .value on a field that does not exist

I thought we answered this here

If you just want to check do something like this

if(doc['readyCreatedTime'].empty) {
  emit(0);
  return;
}

long datenow = new Date().getTime();
long datewas = doc['readyCreatedTime'].value.getMillis();
long days = (datenow - datewas) / 86400000;
emit (days);

Thank you !!
Here I am checking the condition and calculating the hours.
The below script is working for me

int i = doc['readyCreatedTime'].size();

if(i==0){

long datenow = new Date().getTime();

long datewas = doc['createdTime'].value.getMillis();

long milisecondnd=datenow - datewas;

long second=milisecondnd/1000;

long hours=second/3600;

emit(hours);

}

else{

long datenow = doc['readyCreatedTime'].value.getMillis();

long datewas = doc['createdTime'].value.getMillis();

long milisecondnd=datenow - datewas;

long second=milisecondnd/1000;

long hours=second/3600;

emit(hours);

}

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