web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Creating a simple colorpicker based on a field in a table

(1) ShareShare
ReportReport
Posted on by 329
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:
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    8,952 Super User 2025 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
     
  • Superbunny Profile Picture
    329 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
    8,952 Super User 2025 Season 2 on at
    Creating a simple colorpicker based on a field in a table
    Hi,
     
    Did you try to trace the code of the active method and  active_post method? In order to check control background color current value.
     
    Also try the following code to access your control and set its background color.
     
    FormIntControl formControl = this.formrun().design().controlName(formControlStr(ReqParameters, ProductionQuantitiesColorCtrl))
     as FormIntControl;
    
    formControl.backgroundColor(reqParameters.ProductionQuantitiesColor);
     
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,157

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 883 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 674 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans