Converting scripted field to runtime field

Our stack was updated from version 7.9.3 to version 7.17.9 and I am having to convert some of the scripted fields to the new "runtime" field as it shows scripted fields as depreciated. It looks like some of the time functions have changed and i am having a hard time converting. How can i accomplish the same with a runtime field?

Instant CurDate = Instant.ofEpochMilli(new Date().getTime());
long FakeDate = 956851031000L;
Instant Ddate = doc["d_date"].empty ? Instant.ofEpochMilli(FakeDate) : Instant.ofEpochMilli(doc["d_date"].value.getMillis());
Instant Rdate = doc["r_date"].empty ? Instant.ofEpochMilli(FakeDate) : Instant.ofEpochMilli(doc["r_date"].value.getMillis());

if (doc["d_date"].value == null || !doc.containsKey('d_date') || doc["d_date"].empty) {
    return false;
 } else if (CurDate.isAfter(Ddate) && doc['status'].value.contains('Open')) {
    return true
 } else if (Rdate.isAfter(Ddate) && doc['status'].value.contains('Closed')) {
    return true;
 } else {
    return false;
 }

Hi @ccloutr.alex

runtime fields need to emit() the result instead of returning.
Try with this:

Instant CurDate = Instant.ofEpochMilli(new Date().getTime());
long FakeDate = 956851031000L;
Instant Ddate = doc["d_date"].empty ? Instant.ofEpochMilli(FakeDate) : Instant.ofEpochMilli(doc["d_date"].value.getMillis());
Instant Rdate = doc["r_date"].empty ? Instant.ofEpochMilli(FakeDate) : Instant.ofEpochMilli(doc["r_date"].value.getMillis());

if (doc["d_date"].value == null || !doc.containsKey('d_date') || doc["d_date"].empty) {
    emit(false);
 } else if (CurDate.isAfter(Ddate) && doc['status'].value.contains('Open')) {
    emit(true);
 } else if (Rdate.isAfter(Ddate) && doc['status'].value.contains('Closed')) {
    emit(true);
 } else {
    emit(false);
 }

yes - i have tried this - the field just ends up empty - nothing in it.

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