Works fine, needed some correction. Thanks a lot.
Here is the working version if someone want it :
I can't figure out how to embbed code, sorry
object zfound, zobj;
int zcount, result_id;
if(is_null(name))
{
logf(SIGNIFICANT, "Can't proceed. Values are empty.");
return;
}
send_wait(0, top_object(), "call_attr", "z_nr_concat", "sync_fetch", "STATIC", format("nr=U'%s'", id), -1, 0);
zcount = msg[1];
if (zcount == 0)
{
object new_nr;
send_wait(0, top_object(), "get_co_group");
if (msg_error())
{
logf(ERROR, "New NR: error '%s' on '%s'", msg[0], peristent_id);
return;
}
group_leader = msg[0];
send_wait( 0, top_object(), "call_attr", "z_nr_concat", "get_new_dob", NULL, NULL, group_leader);
if (msg_error())
{
logf(ERROR, "New NR: error '%s' on '%s'", msg[0], persistent_id);
return;
}
new_nr = msg[0];
new_nr.nr = id;
send_wait(0, group_leader, "checkin");
if (msg_error())
{
logf(ERROR, "New NR: error '%s' on '%s'", msg[0], peristent_id);
send_wait(0, group_leader, "uncheck");
return;
}
result_id = new_nr.id;
}
else
{
zfound = msg[0];
send_wait(0, zfound, "dob_by_index", "DEFAULT", (int)(zcount-1), (int)(zcount-1));
zobj = msg[0];
result_id = zobj.id;
}
int result;
result = sindex(name, format("-%d",result_id));
if (result==-1)
{
name=format("%s-%d",name,result_id);
}