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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Syntax to remove last hyphens from string using x++

(0) ShareShare
ReportReport
Posted on by

Hi,

I am new to ax.

how to remove last dash from string using x++.

for eg: want to remove last dash from 10144_10145_1 to 10144_10145 the syntax should apply not to one string it should be the whole column, column name is journal reference Id and table name is McsEmvalAmRJournal Table and from the new string I want to extract the data.  Kindly suggest the syntax and any books for tutorials easy to understand. Below is the attached image which I have to change for the column.

  

and the below syntax is which I have prepared please tell if wrong

select Replace('15120_15121','_','') as newcolumn from AMRJournalTable

Thanks in Advance!!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jasman Profile Picture
    1,413 on at

    Wouldn't:
    select Replace('15120_15121','_','') as newcolumn from AMRJournalTable
    so 10144_10145_1 will become 10144101451 ?

    remove ALL dashes and not only the last ?

    Ax-runtime does not directly accept SQL.

    So

    // Define table buffer to work with
    AMR JournalTable amrJournalTable    amrJTable;

    // Select all records i table amrJournalTable (in current legal entity - this is provided that the table does not save data globally
    while select amrTable
    {

        // Here you get each record (tuple) that is found
        // And we remove the last part of the string "_1" if its there
        // So everything after the last _ is removed
        if(strscan(strReverse(armJTable.newcolumn),"_",1,strLen(armJTable.newcolumn)))))
            info(subStr(x,1,(strLen(armJTable.newcolumn)-strscan(strReverse(armJTable.newcolumn),"_",1,strLen(armJTable.newcolumn)))));  

    }


  • Community Member Profile Picture
    on at

    Hi Jacob thanks for your reply... can I know for what purpose we are using strscan and strReverse.... can we use SET syntax???

    Thanks.

  • Community Member Profile Picture
    on at

    Hi jacob,

    Set Journal reference Id_number=Replace(Journalreferenceid_number,'_',")

    can we use above syntax??

    Thanks.!!

  • jasman Profile Picture
    1,413 on at

    Strscan searches a string for another string and returns the position (integer) in the string of what it finds.

    As strscan only returns the first found instance, strreverse is used to reverse the string so we actually find the LAST instance.

  • jasman Profile Picture
    1,413 on at

    No.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans