Home Forum Nuclos Konfiguration Businessprozesse Automatisch fortlaufende Nummer Aw: Automatisch fortlaufende Nummer

Markus Glitzner

Hier meine aktuelle Version

import org.nuclos.common.collect.collectable.searchcondition.*;
import org.nuclos.server.masterdata.valueobject.*;
import org.nuclos.server.ruleengine.*;
import java.util.*;

public abstract class Helper {

* ...
* @author Markus Glitzner (alias Hugo)
* @version 2011-10-30
* @param sEntity the entity name e.g. Aufträge
* @param sField the entity's number field e.g. auftragsnummer
* @param sKey the name of the number range e.g. Auftragsnummer
public static void NextValue(RuleInterface server, String sEntity, String sField, String sKey) throws NuclosBusinessRuleException {

//only if the object is new
if (server.isObjectNew()){

//get the id of the numbering entry
Integer id;
id = getId(server, "Nummernkreise", "name", sKey);

if (id == null) {
throw new NuclosBusinessRuleException("Der Nummernkreis " + sKey + " ist nicht vorhanden!");
//get the MasterDataVO of Nummernkreis
MasterDataVO item = server.getMasterData("Nummernkreise", id);

//get the values from Nummernkreis
String prefix = (String)Nz(item.getField("prefix"), "");
Integer padcount = (Integer)Nz(item.getField("padcount"), 0);
Integer nextvalue = (Integer)Nz(item.getField("nextvalue"), 1);

//set the new number to the called entity
String format = String.format("%%0%dd", padcount);
server.setFieldValue(sEntity, sField, prefix + String.format(format, nextvalue));

//set the new value in Nummernkreis
server.setFieldValue("Nummernkreise", id, "nextvalue", nextvalue+1);

private static Integer getId(RuleInterface server, String sEntity, String sField, String sKey) {
CollectableComparison cond = org.nuclos.common.SearchConditionUtils.newMDComparison(org.nuclos.server.common.MasterDataMetaCache.getInstance().getMetaData(sEntity), sField, ComparisonOperator.EQUAL, sKey);
Collection ids = server.getMasterDataIds(sEntity, new org.nuclos.server.genericobject.searchcondition.CollectableSearchExpression(cond));

if (!ids.isEmpty()) {
return (Integer)ids.iterator().next();
return null;

private static Object Nz(Object o, Object defaultvalue) {
if (o != null) {
return o;
return defaultvalue;