Wednesday, April 7, 2010

Labels with line breaks

Labels can contain line breaks. For example, “Text1\nText2” (let it has ID @LBL1).

However, if you’ll try to display this label “as is”, the result will be not expected:
Box::info("@LBL1");
Gives


To get the expected message with line break strFmtLB() method should be used:
Box::info(strFmtLB("@LBL1"));
Gives

14 comments:

  1. Very useful and thanks very much.

    ReplyDelete
  2. Thanks works in AX 2012.

    ReplyDelete
  3. Obrigado! Thanks! From Brazil.

    ReplyDelete
  4. Is it Possible to break lines for labels in other objects like forms,tables etc?

    ReplyDelete
  5. Does work in AX 2009, see the message info line in my code, this works really well cheers Stasiak
    static void TBP_SS_DialogSampleCode(Args _args)
    {
    Dialog dialog;
    DialogField fieldSalesOrder;
    DialogField fieldQty;
    DialogButton dialogBut;
    str message;
    str messageInfo;
    str messageSO;
    str messageQty;


    ;
    dialog = new Dialog("SalesOrder_Qty_Change");
    message = "";

    dialog.addText("Enter the Sales Order");
    fieldSalesOrder = dialog.addFieldValue(typeId(Description),
    message, "SO", "SO & Qty");
    dialog.addText("Enter the revised Qty");
    fieldQty = dialog.addFieldValue(typeId(Description),
    message, "Qty", "SO & Qty");


    dialog.run();

    if (dialog.closedOk()
    && (fieldSalesOrder.value() != "")
    && (fieldQty.value() != ""))
    {

    messageSO = "Entered Sales Order " + fieldSalesOrder.value();
    messageQty = "Entered A QTY Of " + fieldQty.value();
    messageInfo = messageSO + "\n" + messageQty;
    dialogBut = Box::yesNoCancel(messageInfo, DialogButton::No, "Message");
    if (dialogBut == DialogButton::No)
    {
    info(strfmt( "The No button was clicked."));
    }
    if (dialogBut == DialogButton::Yes)
    {
    info(strfmt("Sales Order " + strfmt(fieldSalesOrder.value())));
    info(strfmt("Sales Order QTY " + strfmt(fieldQty.value())));
    }
    }
    else
    {
    if (fieldSalesOrder.value() == "")
    {
    error("No Sales Order Value");
    warning("You must Enter a Valid SO");
    }
    if (fieldQty.value() == "")
    {
    error("No Sales Ordsdr QTY Value");
    warning("You must Enter a Valid Qty");
    }
    }
    }

    ReplyDelete
  6. HI,

    I have a small issue, can you please help me. I have a code like below, the output shows in single line. I want to show in seperate lines.Please help me. I tried it all ways like \r\n and strFmtLB Thanks in advance.

    static void XMLReadVendorList(Args _args)
    {
    XMLDocument doc;
    XMLNode nodeRoot,
    nodeRecID,
    nodeCreatedDateTime,
    nodeVendGroup,
    nodeVendAc,
    nodeCompanyID,
    nodePurchaseOrderNum,
    nodePurchaseOrderCreatedDateTime,
    nodeVendorName,
    nodeUnitPrice;
    XMLParseError xmlError;
    int i;

    doc = new XMLDocument();
    doc.load("C:\\Result.xml");

    xmlError = doc.parseError();

    if(xmlError && xmlError.errorCode() != 0)
    {
    throw error(strFmt("Error: %1",xmlError.reason()));
    }

    nodeRoot = doc.documentElement();

    nodeRecID = nodeRoot.selectSingleNode("//IDENTITY_KEY_");

    nodeCreatedDateTime = nodeRoot.selectSingleNode("//DATE_TIME_");
    nodeVendGroup = nodeRoot.selectSingleNode("//VENDOR_TYPE_");
    nodeVendAc = nodeRoot.selectSingleNode("//VENDOR_NO_");
    nodeCompanyID = nodeRoot.selectSingleNode("//COMPANY_ID_");
    nodePurchaseOrderNum = nodeRoot.selectSingleNode("//ORDER_NO_");
    nodePurchaseOrderCreatedDateTime = nodeRoot.selectSingleNode("//ORDER_DATE_");
    nodeVendorName = nodeRoot.selectSingleNode("//CUSTOMER_NAME_");
    nodeUnitPrice = nodeRoot.selectSingleNode("//VENDOR_ACTL_COST_");

    info(("nodeRoot.text()"));
    }

    ReplyDelete