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
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
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:
Hi,
Please refer below link
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148