Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Unable to set Account flag color with related Case

Posted on by Microsoft Employee

Hi All

The requirement is :
There will have three case c1, c2, c3 the color of the flag willl all have red color .
then associated account of the cases will be also have the red color flag on it .
code for set flag color on case :
<html><head>
<script src="ajax.googleapis.com/.../jquery.min.js"></script>
<script src="maxcdn.bootstrapcdn.com/.../bootstrap.min.js"></script>
<link rel="stylesheet" href="maxcdn.bootstrapcdn.com/.../bootstrap.min.css">
<script>
$( document ).ready(function() {
alert( "ready!" );
var value =window.parent.Xrm.Page.getAttribute('new_healthreport').getValue();
//alert(value);

if (value =="null" || value ==0){
document.getElementById("abc").style.color = "blue";
//alert("blue");
window.parent.Xrm.Page.getAttribute('new_flagcolor').setValue("Blue");

}
else if (value ==1 || value < 5) {
//alert("1");
document.getElementById("abc").style.color = "red";
//alert("red");
window.parent.Xrm.Page.getAttribute('new_flagcolor').setValue("Red");

}
else if (value == 5 || value < 10){
document.getElementById("abc").style.color = "orange";
//alert("orange");
window.parent.Xrm.Page.getAttribute('new_flagcolor').setValue("Orange");
}
else if (value == 10 || value < 15){
document.getElementById("abc").style.color = "green";
//alert("green");
window.parent.Xrm.Page.getAttribute('new_flagcolor').setValue("Green");
}
else if ( value >= 15){
document.getElementById("abc").style.color = "yellow";
//alert("yellow");
window.parent.Xrm.Page.getAttribute('new_flagcolor').setValue("Yellow");
}

});

</script>
<style>
.orange {
color: orange;
font-size: 24;
}
.blue {
color: blue;
font-size: 24;

}
.green {
color: green;
font-size: 24;

}
.red{
color: red;
font-size: 24;
}
.yellow{
color: yellow;
font-size: 24;
</style>
<meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta><meta></head>
<body style="overflow-wrap: break-word;">
<p id="abc">âš‘</p>
</body></html>

Code for ghet reclate account :
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/incidents?$select=_new_caseaccid_value&$expand=new_asdfId($select=name,new_health,new_newflagcolour)&$count=true", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
var recordCount = results["@odata.count"];
for (var i = 0; i < results.value.length; i++) {
var _new_caseaccid_value = results.value[i]["_new_caseaccid_value"];
var _new_caseaccid_value_formatted = results.value[i]["_new_caseaccid_value@OData.Community.Display.V1.FormattedValue"];
var _new_caseaccid_value_lookuplogicalname = results.value[i]["_new_caseaccid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
//Use @odata.nextLink to query resulting related records
var new_asdfId_NextLink = results.value[i]["new_asdfId@odata.nextLink"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

Thanks .

  • Suggested answer
    ThomasN Profile Picture
    ThomasN 3,190 on at
    RE: Unable to set Account flag color with related Case

    Hi Abhishek, thanks for reaching out.

    You do not need to do this with custom code. If the field you are looking at can be converted to an option set, you can set a color value for each item. Below is the link to the MS documentation and another to CRM Chartguy who is a great resource to follow BTW.

    docs.microsoft.com/.../create-edit-global-option-sets

    crmchartguy.com/.../use-color-codes-from-option-sets-in-both-dynamics-365-charts-and-power-bi

    Let us know if using an option set is not going to work.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans