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

Notifications

Announcements

No record found.

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
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    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
    Stang Profile Picture
    5 on at

    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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans