Adding dynamically UserControls to a report with X++

This is a pretty simple example how to add an UserControl to an existing Report. But since the documentation isn’t talking a lot about here’s the code:

 public boolean fetch() {
    ReportSection reportSection;
    ReportTextControl textControl;
    ;

    reportSection = element.design().autoDesignSpecs().addProgrammableSection(0);

    textControl= reportSection.addTextControl("Hello World");
    textControl.fontSize(20); //do something with your UserControl
    
    reportSection.executeSection();

    reportSection.delete(); //since we don't want to persist this section...

    return true; //true since the execution of the report should continue
}

Everything you need to do is to create a new report and overwrite the method fetch() with the code above.

Have a look at the links I added to the source-code for further information.