Get a particuler postion value from a string value

   Here im getting the values which are placed right side of the symbol "-". and adding next value to it 

using x++ in d365 fo.

   a simple way to increment string values as per the requirement.

sample code:

[Extensionof(formDataSourceStr(LedgerJournalTransDaily,LedgerJournalTrans))]

public final class LedgerJournalTrans_Extension

{

void initValue()

{

int i;

str iNnum,test;

FormDataSource fds = this;

LedgerJournalTrans ledgerJournalTransloc2;

LedgerJournalTable ledgerJournalTableloc;

LedgerJournalTrans ledgerJournalTransloc = fds.cursor();

FormRun formrun;

next initValue();



Args args = new Args();


formrun = element.args().caller();

ledgerJournalTableloc =formrun.dataSource().cursor() as LedgerJournalTable;

Info(ledgerJournalTableloc.JournalNum);

select ledgerJournalTransloc2 ORDER by RecId desc

where ledgerJournalTransloc2.JournalNum == ledgerJournalTableloc.JournalNum;

if(ledgerJournalTransloc2.InvoiceNum)

{

test = ledgerJournalTransloc2.InvoiceNum;

     //by this higleted code we can split and get the required value from the string.

iNnum = subStr(test ,strFind(test,"-",1,strLen(test))+1,strLen(test));

//i = ledgerJournalTransloc2.recid+1;

i = str2Int(iNnum)+1;

ledgerJournalTransloc.InvoiceNum = ledgerJournalTableloc.JournalNum +'-'+ int2Str(i);

Info(strFmt("%1",i));

}

else

{

ledgerJournalTransloc.InvoiceNum = ledgerJournalTableloc.JournalNum +'-'+"1";


}

//InvoiceNum.text(ledgerJournalTableloc.JournalNum);

Info(ledgerJournalTransloc.InvoiceNum );

}


}

No comments:

Post a Comment