Task-2: JavaScript & HTML

 Task-2: JavaScript & HTML 

User Story: - 

On click of case Reject button, show popup with reject reason text, once filled and submitted, reject reason field should get filled and case should be in read only. 

Sudo Code: - 

  • ⇨ Create an HTML web resource with an HTML page with an input field and two buttons Submit and Cancel. 

  • Create a JavaScript web resource with a function, in this function we need to write code to navigate to the web resource. 

  • Read the input value in the reject reason input field 

  • Use window.returnValue method to return the reject reason value. 

  • Get the return value from success callback function and update it in the reject reason field. 

  • Set the Status to Cancelled, it will make the form disabled. 

  • Add the Status field to the form and hide the field. 

  • Set the status code equal to 2 (which means Cancelled). 

  • Save the page using formContext.data.save method. 

  • Create a Reject button using Ribbon work bench. 

  • Add this JavaScript function as action to that Reject button and publish it. 

 

 

 

On click of Reject button HTML page should open with reject reason update it in the form and make form read only 

 

 

HTML Code: - 

 

<html>
    <head>
       
        <style>
            body{
                padding:"15px";
            }
            .text {
                padding:"15px";
                color:"#3258a8";
            }
            .button {
                padding-right:10px ;
            }
        </style>
    </head>
    <body>
        <script>
            let SubmitButton = document.getElementById("SubmitButton");
            let CancelButton = document.getElementById("CancelButton");

            function OnSubmitClick() {
                let reason = document.getElementById("rejectReason").value;
                if (reason != null){
                    window.returnValue= reason;
                    window.close();
                }
               
            }
            function OnCancel() {
                window.close();
            }
           
        </script>
        <label  class="text" for="rejectReason">Reject Reason</label>
        <br/>
        <input class ="button" id="rejectReason" placeholder="Enter the Reject Reson">
        <br/>
        <br/>
       
       
        <button id="SubmitButton" class ="button" onclick="OnSubmitClick()">Submit</button>
        <button id="CancelButton" onclick="OnCancel()">Cancel</button>
    </body>
</html>


 

 

=> Create a JavaScript web resource 

 

 

JavaScript code: - 

 

function OpenHTMLwebresource(primaryControl){
    var formContext = primaryControl;
    var PageInput = {pageType:"webresource", webresourceName: "naree_Reject_Reason"};
    var NavigatipnOptions = { target:2, height: 400, width: 600 , position:1, title: "Reject reason"};
    Xrm.Navigation.navigateTo(PageInput, NavigatipnOptions).then(
        (result) => {
            if(result.returnValue != null ){
                formContext.getAttribute("new_rejectreason").setValue(result.returnValue);

                // to make form disable we need to set status code to 2. (2 == Canceled)
                formContext.getAttribute("statecode").setValue(2);
                formContext.data.save();
 
            }
           
        }
    )  
}

 

 

 

Create a Reject Button: - 

 

 Result: -



 

Comments

Popular posts from this blog

Using Shared Variables in Plug-in and send an email inside the CRM User using Plugin

How to create an Azure AD(Active Directory) and create an application to connect Dynamics 365 from console application

Task-8 : Updating Project Start Date and End Date