Skip to main content

Notifications

Microsoft Dynamics CRM forum
Suggested answer

Setting field color

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

Categories:
  • Suggested answer
    Stang Profile Picture
    Stang 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
    Community Member Microsoft Employee 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
    Pradeep Rai 5,490 Super User 2024 Season 2 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

Dynamics 365 Community Update – Sep 16th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans