﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
<link rel="stylesheet" type="text/css" href="../Styles/Crmstyle.css" /> 
<script type="text/javascript" src="../Scripts/jquery1.9.1.js"></script>
<script type="text/javascript" src="../Scripts/json.js"></script>
<script src="../../../ClientGlobalContext.js.aspx"></script>
<script type="text/javascript">

    var webApiUrl = window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";

    window.onload = function () {
        RetrieveOptionSetAttributeMetadata( "e3fe4ff2-a630-49bb-a1e9-debc3a076815", "51f11b58-be67-4221-a1a7-a5440b4e48ba" ); //incident statuscode
    }
    //////////////***************Retrieve & Load Case Optionset Values Start********************///////////////////

    function RetrieveOptionSetAttributeMetadata( entityName, attributeName )
    {
        var filterQuery = "EntityDefinitions(" + entityName + ")/Attributes(" + attributeName + ")/Microsoft.Dynamics.CRM.StatusAttributeMetadata/OptionSet?$select=Options";
        
        var httpReq = new XMLHttpRequest();
        httpReq.open( "GET", webApiUrl + filterQuery, false );
        httpReq.setRequestHeader( "Accept", "application/json" );
        httpReq.setRequestHeader( "Content-Type", "application/json; charset=utf-8" );
        httpReq.setRequestHeader( "OData-MaxVersion", "4.0" );
        httpReq.setRequestHeader( "OData-Version", "4.0" );
        httpReq.send( null );

        if ( httpReq.status === 200 ) {
            var statusValueColl = JSON.parse( httpReq.responseText ).Options;
            for ( var i = 0; i < statusValueColl.length; i++ ) {
                if ( statusValueColl[i].State == 0 ) {
                    $( '#SelectStatusReason' ).append( '<option value="' + statusValueColl[i].Value + '">' + statusValueColl[i].Label.UserLocalizedLabel.Label + '</option>' )
                }
            }
        }

        if ( window.parent.Xrm.Page.getAttribute( 'iotap_reopenedcasestatusreasonnumber' ).getValue() != null ) {
            $( '#SelectStatusReason' ).val( window.parent.Xrm.Page.getAttribute( 'iotap_reopenedcasestatusreasonnumber' ).getValue() );
        }

    }
    
    //////////////***************Retrieve & Load Case Optionset Values End********************///////////////////
    function UpdateAttribute() {
        var selectedStatusReason = SelectStatusReason.value;
        var statusreason = "iotap_reopenedcasestatusreasonnumber";
        var statusreasonnumber = Number(selectedStatusReason);
        window.parent.Xrm.Page.getAttribute(statusreason).setValue(statusreasonnumber);
    }
</script>
        <style type="text/css">
        .label
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            font-weight: normal;
        }
        .label1
        {
            font-family: Segoe UI, Tahoma, Arial;
            font-size: 11px;
            font-weight: normal;
            color: Red;
        }
        .body
        {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
            background-color: White;
            padding: 0px;
        }
        .style1
        {
            width: 8%;
        }
        .style2
        {
            width:42%;
        }
        .style3
        {
            padding-left:10px;
            width: 8%;
        }
    </style>
</head>
<body style="width:100%;margin:0 0 0 0;padding:0 0 0 0;">
<table style="width: 100%; border-style: none; table-layout: fixed;" cellpadding="0"
        cellspacing="0">
<colgroup>
            <col width="108">
            <col>
            <col width="123">
            <col>
            <tbody>
        <tr>
            <td align="left"style="width:8%">
                <label class="label">Re-Open Case Status Reason</label></td>
            <td width="92%" >
                <select id="SelectStatusReason" class="ms-crm-SelectBox" name="D1" onchange="UpdateAttribute()" >
                    <option ></option>
                </select></td>
        </tr>
        </tbody>
        </table>
</body>
</html>
