Force Boolean value to be "true" or "false", instead of "Yes" or "No"

MarHanMarHan Member Posts: 34
edited 2023-07-13 in NAV Three Tier
Hi community,

I need to write a boolean value to an xml file and am always getting a "Ja" (German for Yes), instead of a "true". I've tried all of the options shown here under "Standard Boolean Format" (Link) but without success. And I don't wanna do stuff like "if value = 1 then 'true' else 'false'" or so.

Does anyone have a clue for me?

Thanks in advance,

Markus

Best Answer

  • vaprogvaprog Member Posts: 1,139
    Answer ✓
    What are you doing? Do you compose an XML document as Text? Don't! Use an XmlPort or XML DOM Management Codeunit or whatever else is available in your environment to properly generate XML documents.

    What type of object is "cims:value". If it is not of datatype Boolean, obviously FORMAT(...,9) will not have the desired effect here.

Answers

  • AlexDenAlexDen Member Posts: 86
    Hi,

    You have to use FORMAT(Value,0,9) to get XML-formatted value.
    This applies not only to Boolean, but also to the Int, Decimal, and Date data types.
  • MarHanMarHan Member Posts: 34
    Hi,

    unfortunately I am doing exactly this:

    h1l2ggacduzc.png

    what results in this

    69n63q8dl2ke.png

    :-(

    Regards

    Markus
  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Hello,

    I'd try it with (temporarily) changing the language setting (https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-globallanguage-method). Change the language to english before formatting the value, then back to the original language. Pseudo code:

    OriginalLanguageId := System.GlobalLanguage();
    System.GlobalLanguage(1033); // change to english
    FormattedBooleanValue := FORMAT(BooleanVariable, 0, 9);
    System.GlobalLanguage(OriginalLanguageId); // change back

    Best Regards,
    Thomas
  • MarHanMarHan Member Posts: 34
    Hi Thomas,

    sounded really good but does not work either:

    kfcv5b72a8ah.png

    Debugger:

    iht89ngmiu65.png

    Best regards

    Markus
  • ThomasHagenmeyerThomasHagenmeyer Member Posts: 14
    Hi Markus,

    I'm not working in AL yet, but C/AL ... I made a short test:

    zqhcoyyn3huj.png

    So, the language change doesn't help (yielding 'Yes'), but XML format by specifying 9 works...
    This is just wild guessing: I think you are using a table field as the parameter for the Format function. Maybe in AL it works different for a field object compared to a plain boolean variable?

    Best Regards,

    Thomas
  • vaprogvaprog Member Posts: 1,139
    Answer ✓
    What are you doing? Do you compose an XML document as Text? Don't! Use an XmlPort or XML DOM Management Codeunit or whatever else is available in your environment to properly generate XML documents.

    What type of object is "cims:value". If it is not of datatype Boolean, obviously FORMAT(...,9) will not have the desired effect here.
  • MarHanMarHan Member Posts: 34
    Hi vaprog,

    I'm doing this "manually" as it is a nightmare using XML DOM Mgt Codeunit when you need to deal with different xml namespaces and so on. The xmls have a rather simple structure so much easier and less frustrating.

    And you we're absolutely right: Due to a copy and paste mistake my variable "cmis:value" still was a text not a boolean. Having changed it to boolean it works now. Even without the language change that Thomas suggested.

    Thanks guys!
Sign In or Register to comment.