Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Slash '\' appears when using con2str()

(0) ShareShare
ReportReport
Posted on by 130

Dear experts,

I have a form that shows data of GeneralJournalEntry table data, and a button Print. When the button is clicked, the selected records's JournalNumber in grid will be sent to query LedgerTransPerJournal as range. I created a container that stores the selected records's journalNumber, when I set the container data as range in query, there are some '\' appear after each journalNumber. I don't how why it happened, the method i used is con2str().

This is my code of Print button:

void clicked()
{
    GeneralJournalEntry     locGeneralJournalEntry;
    Query                   q;
    QueryRun                qrun;
    container               conJournalNum;
    
    locGeneralJournalEntry      = GeneralJournalEntry_ds.getFirst(true);
    q                           = new Query(queryStr(LedgerTransPerJournal));
    q.dataSourceTable(tableNum(GeneralJournalEntry)).clearRanges();
    
    if (!locGeneralJournalEntry)
    {
        warning('Voucher lines must be selected');   
        return;
    }
    else
    {
        while (locGeneralJournalEntry)
        {
            //info(strFmt('%1', locGeneralJournalEntry.SubledgerVoucher ));     
            //q.dataSourceTable(tableNum(GeneralJournalEntry)).addRange(fieldnum(GeneralJournalEntry, JournalNumber)).value(SysQuery::value(locGeneralJournalEntry.JournalNumber));
            conJournalNum += [queryValue(locGeneralJournalEntry.JournalNumber)];
            locGeneralJournalEntry = GeneralJournalEntry_ds.getNext();
        }
        q.dataSourceTable(tableNum(GeneralJournalEntry)).addRange(fieldnum(GeneralJournalEntry, JournalNumber)).value(SysQuery::value(con2Str(conJournalNum)));
        qrun    = new QueryRun(q);
        qrun.prompt();
    }
}

This is the screen of QueryForm:

7838.Untitled.png

*This post is locked for comments

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,235 Most Valuable Professional on at
    RE: Slash '\' appears when using con2str()

    It's the expected behavior of your code. It says that you want to find JournalNumber GJT-001893,GJT-001894,GJT-001895 and it escapes special characters in the string by calling SysQuery::value(). It will look for the literal value "GJT-001893,GJT-001894,GJT-001895", not for three different values.

    You could fix it by removing SysQuery::value(), but it would still be problematic. For example, if you have many records, you can exceed the allowed length of query range values. Your code is also more complicated than needed. Get rid of all these problems by simply creating several ranges for the JournalNumber field:

    QueryBuildDataSource journalEntryDs = q.dataSourceTable(tableNum(GeneralJournalEntry));
    FieldId journalField = fieldnum(GeneralJournalEntry, JournalNumber);
    
    ...
    
    while (locGeneralJournalEntry)
    {
        journalEntryDs.addRange(journalField).value(queryValue(locGeneralJournalEntry.JournalNumber));
        
        locGeneralJournalEntry = GeneralJournalEntry_ds.getNext();
    }
  • Long.Thai Profile Picture
    Long.Thai 130 on at
    RE: Slash '\' appears when using con2str()

    Hi Sukrut,

    Thanks for fast reply.

    I have tried also and it is the same, the \ still there

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans