28 March 2014

Split the string value by using saperatror in AX

static void StringSplitter(Args _args)
{
GeneralJournalAccountEntry generalJournalAccountEntry;
TextBuffer buffer;
str value;
Counter cnt;

value = "1000-524-457-524";
//select generalJournalAccountEntry;
buffer = new TextBuffer();
buffer.setText(value);//generalJournalAccountEntry.LedgerAccount);

while (buffer.nextToken(0, '-'))
{
cnt++;

if(cnt == 1)
info (strFmt("first %1",buffer.token()));
if(cnt == 2)
info (strFmt("two %1",buffer.token()));
if(cnt == 3)
info (strFmt("three %1",buffer.token()));
if(cnt == 4)
info (strFmt("four %1",buffer.token()));

}
}

2 comments:

  1. another way you could've done this is using str2con & con2str. interesting take on the matter though

    ReplyDelete
  2. Another way to do it in D365FO/AX

    value = "1000-524-457-524";

    List listLedgerAccounts = new List(Types::String);
    listLedgerAccounts = strSplit(value, '-');
    ListIterator listIterator = new ListIterator(listLedgerAccounts);
    int i = 1;
    while (listIterator.more())
    {
    info(strFmt('Count: %1, Ledger Account: %2', i, listIterator.value());
    i++;
    listIterator.next();
    }

    ReplyDelete

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...