SBX - Search With Button

SBX - Forum Post Title

remove the last comma from the message

Microsoft Dynamics AX Forum

rohit1900 asked a question on 9 Nov 2018 4:46 AM
My Badges

Question Status

Verified

Hi all, 

 this is my job 

static void Job218(Args _args)
{
    SalesTable SalesTable;
    str message;

    while select SalesTable  where SalesTable.SalesStatus == SalesStatus::Delivered
    {
        message = message + strFmt("%1,",SalesTable.SalesId);
    }

    print(message);
    pause;
}

here in the output   in message i am getting an extra comma which i want to remove  so that my message looks like

message = "a,b,c,d" not like "a,b,c,d,"(the extra comma after d in the message )

Reply
Verified Answer

I think it's better if you don't insert the last comma in the first place. Do it like this:

static void Job218(Args _args)
{
    SalesTable SalesTable;
    str message;
    boolean firstLine = true;

    while select SalesTable  where SalesTable.SalesStatus == SalesStatus::Delivered
    {

        if (firstLine)
        {
            message = strFmt(%1",SalesTable.SalesId);
            firstLine = false;
        }    
        else
        {
            message = message + strFmt(", %1",SalesTable.SalesId);
        }

    }

    print(message);
    pause;
}


Reply
Crispin John Augustine responded on 9 Nov 2018 4:54 AM
My Badges
Suggested Answer

replace print(message);

   pause;

with

info(strDel(message, strLen(message), 1));

Reply
Verified Answer

I think it's better if you don't insert the last comma in the first place. Do it like this:

static void Job218(Args _args)
{
    SalesTable SalesTable;
    str message;
    boolean firstLine = true;

    while select SalesTable  where SalesTable.SalesStatus == SalesStatus::Delivered
    {

        if (firstLine)
        {
            message = strFmt(%1",SalesTable.SalesId);
            firstLine = false;
        }    
        else
        {
            message = message + strFmt(", %1",SalesTable.SalesId);
        }

    }

    print(message);
    pause;
}


Reply
Crispin John Augustine responded on 9 Nov 2018 4:54 AM
My Badges
Suggested Answer

replace print(message);

   pause;

with

info(strDel(message, strLen(message), 1));

Reply

SBX - Two Col Forum

SBX - Migrated JS