Thursday, 16 February 2012

Flags and Alerts Web Resource in Microsoft Dynamics CRM 2011

One of the requirements for the project I'm working on is to easily show any alerts or flags against a record. The CRM record itself might record it somewhere on the form, but having a very quick reference or reminder can be quite important.

I thought about going down the Silverlight road, but in this case it didn't need to be too complicated.

The solution is an HTML web resource which looks for the flags and dependent on them will display an alert:


Bad Alert


Good Alert!



The alert in the example above is toggled by the 'Credit Hold' choice, but could easily be used in different ways.

This is the basic web resource, which I haven't cleaned up from my early attempts, but could easily be hacked around to suit:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script> 
    <script type="text/javascript">
        function ContextInformation() {
            document.getElementById('td2').innerHTML = window.parent.Xrm.Page.getAttribute('creditonhold').getValue();
            var result = window.parent.Xrm.Page.getAttribute('creditonhold').getValue();
        }
 </script> 
     <title></title> 

 </head> 
<body onload="ContextInformation();" style="border-bottom: 0px;
    border-left: 0px;
    border-top: 0px;
    border-right: 0px;
    padding-bottom: 0px;
    padding-top: 0px;
    padding-left: 0px;
    padding-right: 0px;
    font-family: Segoe UI, Tahoma, Arial;
    font-size: 11px;
    font-weight: bold;
    background-color: #f6f8fa;" text="White">
     <table class="style1">
 
         <tr> 
         <td> 
         </td> 
             
            <td class="style4"> 
                &nbsp;</td> 
          <td class="style3" id="td2"> 
                 &nbsp;</td>
         </tr> 
    </table>
      
         <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script> 
            <script type="text/javascript">

                document.getElementById('td2').innerHTML = window.parent.Xrm.Page.getAttribute('creditonhold').getValue();
                var result = window.parent.Xrm.Page.getAttribute('creditonhold').getValue();
                //alert(result);
                if (result == true) {
                    document.write('<img alt= "alert2" style="height: 38px; width: 51px" src="http://crm-dev-01:5555/CRMDEV/WebResources/arcrp_alert" /><font color ="Red"><marquee>There is a Flag on this record</marquee></font>');
                }
                else {
                    document.write('<img alt= "alert2" style="height: 51px; width: 51px" src="http://crm-dev-01:5555/CRMDEV/WebResources/arcrp_Smile" />');
                }
</script>

</body>
</html>



1 comments:

  1. Hi thanks for Nice post. Could I ask for a more detailed guide. I am getting an not able to retrive value for : 'creditonhold').getValue();
    When I add it to main form...

    ReplyDelete