Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Unable to change the flag color of the Related Acount

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am unable to change the flag color with the related cases  .

this code will be change the color of the account record

<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() {
var GUIDvalue =window.parent.Xrm.Page.data.entity.getId();
//alert(GUIDvalue);
var str = GUIDvalue.replace("{","").replace("}","");

var fetchdata ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
+" <entity name='incident'>"
+ "<attribute name='new_flagcolor' alias = 'colorstring'/>"
+"<attribute name='customerid' />"
+"<attribute name='title'/>"
+" <attribute name='createdon' />"
+"<attribute name='ownerid' />"
+"<attribute name='incidentid' />"
+" <attribute name='caseorigincode' />"
+"<order attribute='title' descending='false' />"
+"<filter type='and'>"
+"<condition attribute='new_accountcasetestid' operator='not-null' />"
+"<condition attribute='new_flagcolor' operator='not-null' />"
+" </filter>"
+" </entity>"
+"</fetch>";
var fetch = encodeURI(fetchdata);
var entityname = "incidents";
var serverURL =window.parent.Xrm.Page.context.getClientUrl();
var Query = entityname + "?fetchXml=" + fetch;
var req = new XMLHttpRequest();
req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.1/"+ Query, 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() { 
//alert(req.readyState);
if (req.readyState === 4) {
req.onreadystatechange = null; 
//alert(req.status);
if (req.status === 200) {
alert("122");
var results = JSON.parse(req.response);
var test = JSON.stringify(results.value);
alert("123"); 
alert(test);
console.log("--------------"+test);
//alert(results.value[0].colorstring);
console.log("+++++++++++++++++++"+results.value);
for (var i = 0; i < results.value.length; i++) {

if(results.value[i].colorstring=="Red")
{
alert("1")
document.getElementById("abc").style.color ="Red";

}
else if (results.value[i].colorstring =="Green") {
alert("2");
document.getElementById("abc").style.color ="Green";

}
else if (results.value[i].colorstring =="orange") {
alert("3");

document.getElementById("abc").style.color ="orange";

}
else if (results.value[i].colorstring =="pink") {
alert("4");
document.getElementById("abc").style.color ="pink";

}
else if (results.value[i].colorstring =="blue") {
alert("5");
document.getElementById("abc").style.color ="blue";

}
else{
alert("Flag data");
}

}//for loop


} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
//alert ("124");


req.send();


});

</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></head>
<body style="overflow-wrap: break-word;">
<p id="abc">âš‘</p>
</body></html>

please suggest 

Thanks & Regards 

Abhishek 

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Unable to change the flag color of the Related Acount

    Hi,

    can you try to debug the code? which line is failed?

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... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans