web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Long.Thai Profile Picture
    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

  • Verified answer
    Martin Dráb Profile Picture
    237,002 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();
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Willem van Duren Profile Picture

Willem van Duren 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans