This is sample code to Increase Serial number in axapta through code. There are two way to set serial number one is number sequence other is maintain sequence number by code.
This is way to increase serial number if you do not want to use number sequence .
This is way to increase serial number if you do not want to use number sequence .
display str privateMethod()
{
int ss=0;
str SrNo;
ActualWorkDet actualWorkDet1;
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
int total;
;
//itemid="CN-01";
//itemid=Itemhead.itemid();
itemid=ActualWorkHead.ProdId;
if (itemid != "")
{
query = new Query();
queryBuildDataSource =query.addDataSource(tableNum(ActualWorkDet));
//queryBuildDataSource.addSelectionField(fieldNum(CopyOfItemRoutesDet,SrNo),SelectionField::count);
queryBuildDataSource.addSelectionField(fieldnum(ActualWorkDet,SrNo), SelectionField::Max);
//queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildRange =queryBuildDataSource.addRange(fieldNum(ActualWorkDet,ProdId));
queryBuildRange.value(itemid);
queryBuildDataSource.relations(true);
queryRun = new QueryRun(query);
//if (QueryRun.prompt())
{
//itemid=queryRun.args().lookupValue(itemId);
while (queryRun.next())
{
actualWorkDet1 =queryRun.get(tableNum(ActualWorkDet));
total = real2int(actualWorkDet1.SrNo);
}
}
{
//ss=str2int(itemRoutesDet.SrNo) ;
ss=total+1;//ss+1;
//ss=ss + 1;
}
//NumberSequenceReference =numberSequenceReference::find(typeId2ExtendedTypeId(typeid(ItemId)));
//numberSeq = NumberSeq::newGetNum(NumberSequenceReference);
//ss = numberSeq.num();
SrNo=int2str(ss);
Sno=SrNo;
//Sno= Sno + '.00000';
}
ActualWorkDet.SrNo=str2int(Sno);
Return Sno;
}