Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Creating a simple colo...
Finance forum
Suggested answer

Creating a simple colorpicker based on a field in a table

Posted on by 152
I extended the ReqParameters table with an int field, named ProductionQuantitiesColor.
 
I then extended the form with the same name and added a formcontrol for my field.
 
I found an existing Microsoft dropdown on the form JmgProfileTable:
[DataSource]
class JmgProfileTable
{
    public int active()
    {
        int ret;
        ret = super();
        displayColor.backgroundColor(jmgProfileTable.Color);
        return ret;
    }


    [Control("Integer")]
    class displayColor
    {
        public void lookup()
        {
            jmgProfileTable.Color = ColorSelection::selectColor(this, jmgProfileTable.Color);
            displayColor.backgroundColor(jmgProfileTable.Color);
        }

    }
}
 
So I wanted to create the same logic for my reqParameters extension, so I added the following code:
[ExtensionOf(formControlStr(ReqParameters, ProductionQuantitiesColorCtrl))]
final class FormDF_ReqParameters_ProductionQuantitiesColorCtrl_Extension
{
    public void lookup()
    {
        next lookup();
        this.lookup_post();
    }

    public void lookup_post()
    {
         FormDataSource formDatasource = this.formRun().dataSource(tableStr(ReqParameters));
         ReqParameters reqParameters = formDatasource.cursor();
         reqParameters.ProductionQuantitiesColor = ColorSelection::selectColor(this, reqParameters.ProductionQuantitiesColor);
         this.backgroundColor(reqParameters.ProductionInstructionsColor);
         reqParameters.write();
    }
}


[ExtensionOf(FormDataSourceStr(ReqParameters, ReqParameters))]
internal final class FormDS_ReqParameters_ReqParameters_Extension
{
    public int active()
    {
        int ret = next active();
        this. active_post(ret);
        return ret;
    }

    public int active_post(int ret)
    {     
        ReqParameters reqParameters = this.cursor() as ReqParameters;
        if(reqParameters)
        {
            int color =  reqParameters.ProductionQuantitiesColor;
            FormIntControl  formControl  = this.formRun().control(this.formRun().controlId(formControlStr(ReqParameters,                                ProductionQuantitiesColorCtrl)));
            formControl.backgroundColor(reqParameters.ProductionQuantitiesColor);
        }
        return ret;
    }
}
 
The only thing I added is the call to reqParameters.write(), in order to make sure the value gets stored.
 
The integer value gets saved correctly and I also get a colorpicker via the lookup if I open the dropdown.
 
However, when rendering the screen the colorpicker always stays white. I even check in a breakpoint that the call to fromControl.backgroundColor in the datasource's active extension is being called correctly and has the correct integer value as well.
 
Does anyone know what I could be missing here?
Categories:
  • Superbunny Profile Picture
    Superbunny 152 on at
    Creating a simple colorpicker based on a field in a table
    @Waed:
     
    Thank you for your response.
     
    The lookup part of the logic is actually working correctly (the colorpicker window opens and I can select a color, which is then set).
     
    The part that is not working is the initialization. Furthermore you mention extending the datasource, but the part which does not seem to be working IS a datasource extension. I am extending the active method, just like microsoft does in the jmgProfileTable form
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 5,905 Super User 2024 Season 2 on at
    Creating a simple colorpicker based on a field in a table
    Hi,
     
    Usually in order to override lookup in Extension you should follow the following link:
    https://ievgensaxblog.wordpress.com/2018/01/10/d365foe-how-to-override-form-data-source-field-lookup-method/
     
    Give it a try and tell us the result also why you override Form control and form Datasource field, try to add your code at DataSource level.
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     

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

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,818 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,147 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans