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 :
Small and medium business | Business Central, N...
Suggested answer

hex value to colour - control add in

(2) ShareShare
ReportReport
Posted on by
Hello, I want help in developing control add in, where I enter value in business central and I get the colour in another field. So please suggest me the code for the control add in. what wrong am  I doing??? Getting error when entering value in business central field - A DotNet variable has not been instantiated. Attempting to call SetColor in Page demo controladdin card: Color - OnValidate. Page demo controladdin card - 0 has to close.
 
controladdin ColorPreview
{
    Scripts = 'Scripts/colorpreview.js';
    StartupScript = 'Scripts/colorpreview.js';
    RequestedHeight = 30;
    RequestedWidth = 60;
 
    //Events = OnSetColor(hexValue: Text);
 
    Procedure SetColor(hexValue: Text);
}
-------------------------------------------------------------------------------------------------------
color preview js file------
document.addEventListener('DOMContentLoaded', function () {
    var div = document.createElement('div');
    div.id = 'color-preview';
    div.style.width = '100%';
    div.style.height = '100%';
    div.style.border = '1px solid #ccc';
    document.body.appendChild(div);
});
 
function SetColor(hexValue) {
    var container = document.getElementById('color-preview');
    if (container) {
        container.style.backgroundColor = hexValue;
    }
}
window.SetColor = SetColor;
===============================================================================================
page fields---
                 field(Color; Rec."Color Hex")
                {
                    ApplicationArea = all;
                    ToolTip = 'Specifies the value of the Color field.', Comment = '%';
                    trigger OnValidate()
                    var
                        ColorPreview: ControlAddIn ColorPreview;
                    begin
                         ColorPreview.SetColor(Rec."Color Hex");
                    end;
                }
                field(ColorPreviewControl; Rec."Color Hex")
                {
                    ApplicationArea = All;
                    Editable = false;
                    ShowCaption = true;
                    //ControlAddIn = AKI_ColorPreview;
 
                    trigger OnValidate()
                    var
                        ColorPreview: ControlAddIn ColorPreview;
                    begin
                        ColorPreview.SetColor(Rec."Color Hex");
                    end;
                }
 
  • Suggested answer
    Ramesh Kumar Profile Picture
    on at
    hex value to colour - control add in
    Hi,
     
    I hope below link can help you
     
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    Sohail Ahmed Profile Picture
    on at
    hex value to colour - control add in
    Maybe this will help you to resolve your issue
     
     
    Mark this answer as verified if it helps you.
  • Gerardo Rentería García Profile Picture
    on at
    hex value to colour - control add in

    Hi, good day
    I hope this can help you, and give you some hints.

    Change field color based on field value in Dynamics 365 Business Central | Dynamics 365 Lab

    Best Regards
    Gerardo

  • Suggested answer
    YUN ZHU Profile Picture
    on at
    hex value to colour - control add in
    If this is a cloud version, I personally recommend using the method provided by Gerardo.
    Or you could consider using the solution Erik mentioned recently, which also doesn't require an add-in.
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    RockwithNav Profile Picture
    on at
    hex value to colour - control add in
     
    Choose which on can go along.
     
    For Control addin and in SaaS get rid of DotNet Variable. Between JS and CSS I guess you can achieve,

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans