Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Setting this tickbox does however set some properties, which can then be used for emitting items which are more recently updated than the incremental date.


For an example on how to use incremental with a datafeeder, see below code snippet, which will emit all PricelistItems, sorted by most recent update date, from pricelist ID 999:


Paste code macro
languagegroovy

feedObjects("PLI", Filter.equal("pricelistId", 999), "-lastUpdateDate")

void feedObjects(String typeCode, Filter filter = null, String sortBy = null, Boolean supportIncremental = true) {
  List<Number> ids = getObjectIds(typeCode, filter, sortBy, supportIncremental)
  for (id in ids) {
    api.emitPersistedObject(typeCode, id)
  }
}

List<Number> getObjectIds(String typeCode, Filter filter = null, String sortBy = null, Boolean supportIncremental = true){
  if(supportIncremental)
    filter = getIncrementalFilter(filter)

  def stream = api.stream(typeCode, sortBy ?: "-lastUpdateDate", ["id"], filter)
  List<Number> ids = stream?.collect { it.id }
  stream?.close()
  return ids
}

Filter getIncrementalFilter(Filter filter = null){
  if (api.currentItem("incremental") as Boolean) {
    Filter timeFilter = Filter.greaterOrEqual("lastUpdateDate", api.currentItem("incCalculationDate") ?: api.currentItem("incLoadDate"))

    if (filter)
      filter = Filter.and(filter, timeFilter)
    else
      filter = timeFilter
  }
  return filter
}