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 :
Customer experience | Sales, Customer Insights,...
Suggested answer

Setting field color

(0) ShareShare
ReportReport
Posted on by 5

Good morning,

I am attempting to set a field color based on contents of some other fields;

I referred to : Change Field Color in MS CRM 365 (msdynamiccrmcustomizations.blogspot.com)

The field I am looking at is in a Tab called: Order Product Families (Label is the same).

The field is: sop_australianshutterduedate

Note that I am happy to set either/both the label and field to say Green depending on conditions:

My Javascript onLoad first few lines look like this;

   var formContext=executionContext.getFormContext();

Then I do the first step (from attached article)

 var scandoc = parent.document.getElementById("sop_australianshutterduedate");

and that is as far as I can get - because scandoc is returned as null..................

Can anyone advise - because if I cannot get past this first step, obviously I cannot set the color...........

All the best

Stan

I have the same question (0)
  • Suggested answer
    Stang Profile Picture
    5 on at
    RE: Setting field color

    Hi All,

    Thanks for the responses.

    Unfortunately I could not get the JavaScript methods to work - plus they are unsupported and may go away so..........

    What I did was to make a three value option set with values Green, Amber and Red) and populated the form.

    Then applied the PCF  PcfColorfullOptionSetButtomSolution.

    The via flow (Power automate) on order update (filtering to the EXP date fields), I reset the optionset values depending on the comparison of Due date/Exp Date

    All in all a very acceptable solution to the issue - and it looks very nice.

    Stan

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Setting field color

    Hi Stang,

    As Pradeep Rai said, using JS to modify the DOM in the CRM is not recommended.

    If you would like to do it by JS, please refer to the following code( I tested the code in the thread Pradeep Rai provided, it can't work on my side):

    for lable:

    parent.$("[title='<your label name> - <your field description>'").css("color", "green");

    for field:

    parent.$("[data-id='<your field name>.fieldControl-(suffix)'").css("color", "green");

    The suffix is determined by the filed type:

    text       ----    text-box-text

    Yes/No ----    checkbox-select

    Choice ----    option-set-select

    .......(You can press F12 to get suffix)

    Here is my test code(create a onLoad event on my form):

    function formOnLoad(executionContext){
        var time = 0;
    	var myInterval = setInterval(changeColor, 100);
    	function changeColor() {
    		var addTask = parent.$("[data-id='cr5a6_addtask.fieldControl-checkbox-select']");
    		var twitter = parent.$("[data-id='msdyusd_twitter.fieldControl-text-box-text']");
    		var category = parent.$("[data-id='accountcategorycode.fieldControl-option-set-select']");
        	if (addTask.length > 0 && twitter.length > 0 && category.length > 0) {
    			addTask.css("color", "green");
                parent.$("[title='addTask - Please add a Task.']").css("color", "green");
                twitter.css("color", "red");
                parent.$("[title='Twitter - Capture the twitter id']").css("color", "red");
                category.css("color", "blue");
                parent.$("[title='Category - Select a category to indicate whether the customer account is standard or preferred.']").css("color", "blue");
    			clearInterval(myInterval);
        	}
            time  ;
            console.log(time);
    	}
    }

    Result:

    pastedimage1632468724837v1.png

  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    RE: Setting field color

    Hi,

    Please refer below link 

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/285573/need-change-the-colour-of-text-field-value-in-dynamics-365/1161059

    But I would suggest, do not modify the DOM element of CRM it is not supported way.

    Instead DOM manipulation use PCF control. 

    Please refer below control.

    https://pcf.gallery/pcf-color-field/

    Thanks,

    Pradeep.

    Please mark this as VERIFIED if it helps.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 141

#2
DAnny3211 Profile Picture

DAnny3211 134

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans