Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Prefixual

    CodeSOD: Prefixual

    July 16, 2024

    Maciek has the distinct pleasure of working on Dynamics Ax, and ERP system. Like every other ERP system, it’s endlessly customizable, and scriptable. In this case, scriptable in a custom language called “X++”.

    While it’s probably entirely possible to write good code under these circumstances, it’s not an environment conducive to that. And that’s how Maciek inherited this method:

    public boolean modified()
    {
    boolean ret;
    str itemPrefix;

    str itemId;
    ResponseCodeTable responseCodeTable;
    ;

    itemId = SalesLine_ItemId.getLine(1);
    if (itemId)
    {
    itemPrefix = strupr(strkeep(substr(itemId, 1, 2),“qwertyuiopasdfghjklzxcvbnm”));

    responseCodeTable = ResponseCodeTable::existItemPrefix(itemPrefix);
    if(responseCodeTable)
    {
    itemId = substr(itemId, strlen(itemPrefix)+1, strlen(itemId) – strlen(itemPrefix));
    if (InventTable::exist(itemId))
    {
    this.pasteText(itemId, false);
    SalesLine.PrefixItem = itemPrefix;
    if(!ResponseCodeTable::findById(salesTable.ResponseCodeId).SuppressLineLevelPricing)
    SalesLine.ResponseCodeId = responseCodeTable.ResponseCodeId;
    }
    }
    }

    ret = super();

    return ret;
    }

    Now, this is a function called modified which returns a boolean value. This leads me to believe that this function is checking if a record is dirty- it returns true if the record has been modified and not saved to the database.

    That is not what it does.

    We start by getting an item ID from the first line of the SalesLine_ItemId. If it has one, we then extract its prefix- we use substr to grab two characters, filter the characters to just alphabetic characters, and convert to upper case. The purpose here is to validate the expected format of our item prefix- two alphabetic characters. If the item ID isn’t in the correct format, we’ll get something other than two characters in our itemPrefix variable.

    Then we call ResponseCodeTable::existItemPrefix, using that itemPrefix. You may assume that this is just doing an existence check- but note the variable we’re stuffing the return in. It’s type is ResponseCodeTable- this does not check for existence, but actually queries the database for full records.

    If there is a record, we do some string munging, call a different exist method (for inventory records?), and then populate a few fields on our SalesLine.

    Finally, we call super() and return its value- which probably is doing what we expected the function to do in the first place, which is check if the record is dirty or not.

    The irony here, is that because we’re manipulating the record under examination, we might have made it dirty just by validating it. I think. I don’t know, because it’s impossible to understand this function in isolation. It’s far off from the single responsibility principle, and instead is doing multiple things. This is likely because we needed to hook this functionality in some where, and based on the lifecycle of data in Dynamics Ax (or these scripting extensions), this looked like the most convenient place to do it.

    I’ve seen this kind of code a lot. I’ve written a fair bit of this kind of code: you need a new feature, there’s no good place to hook the functionality in, so you find a place that touches the right part of the lifecycle and just wedge this into there. Voila, feature works, release it, and users are happy.

    Technical debt becomes a problem for future you, or more likely, your successor.

    A special shoutout to how they list off their alphabet by just following the QWERTY keyboard layout. That, itself, is the real WTF, as we all know the correct layout should have been “pyfgcrlaoeuidhtnsqjkxbmwvz”.

    [Advertisement]
    BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCSS Selectors
    Next Article CodeSOD: Sanitary Paths

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Turning Music Into Motion: The Making of the 24/7 Artists Launch Page

    News & Updates

    TokenSkip: Optimizing Chain-of-Thought Reasoning in LLMs Through Controllable Token Compression

    Machine Learning

    Netflix Adds ChatGPT-Powered AI to Stop You From Scrolling Forever

    Artificial Intelligence

    Everything you need to know about Lottie animations

    Web Development
    Hostinger

    Highlights

    How to fetch / read data into MySQL database using Laravel 11

    February 10, 2025

    In the previous tutorial, we learnt how to insert data into the database using Larave…

    The tiniest Raspberry Pi – the $5 Pico 2 – gets a big performance boost

    August 8, 2024

    10+ Tools & Resources for Designers and Agencies in 2025

    February 11, 2025

    I tried the new Gemini button in Google Photos – and classic search is officially history

    April 15, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.