Java script Task-2: Onclick 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.

 If you click on Reject button then show one pop up with empty text box if you enter any data in that text box then that data will updated into Reject reason field and case form should convert in to Read only format.

*      Create one Reject button in case entity by using Ribbon workbench

*      Write Html code for popup design

*      After writing the Html code create new web Resource and choose type as Web-Page (Html).

*      Write java script code and add this code into web resource.

  In java script code:

·         Choose page type as Web resource

·         Choose web Resource name=Html web resource name

·         In java script code need to specify the popup height, width, position and Target.

·         Retrieve the reject reason field value from case entity

·         Set the reject reason value as Approved.

*      Add this java script web resource to Reject button. 


 

Html code:

<html>

<head>

</head>

<body>

  <h1>hello</h1>

    <script>

        function SubmitClick()

        {

            let val = document.getElementById("popup").value;

            window.returnValue = val;

            window.close();

        }

        function cancelClik()

        {

            window.close();

        }

    </script>

    <form id="onlyForm">

        <input type="text" id="popup" name="RejectReason" placeholder="Enter the Reason"/>

        <input type="submit" value="submit" onclick="SubmitClick()"/>

        <input type="button" value="Cancel"onclick="cancelClik()"/>

    </form>

</body>

</html>

 

Go to the solution and choose web Resource à Add web Resource à choose type as Webpage(Html)

 


 

Click on Text Editor and choose Source and Paste Html code here

Click on Ok and Publish.

 


Java script code:

function Popup(PrimaryControl) {

    var pageInput =

    {

        pageType:"webresource",

        webresourceName:"effi_Popuphtml"

    };


    var navigationOptions = {

        target: 2,  // value: 1 it opens the page inline , value: 2 it opens the page in a pop-up format

        width: 400,  //width of the pop-up

        height: 300,  //height of the pop-up

        position: 1 //value:1 it opens the pop-up in the center of the screen, value:2 opens the pop-up on the side of the screen similar to a side bar

    };


    //navigate To is a build in method by microsoft

    Xrm.Navigation.navigateTo(pageInput, navigationOptions).then(

        function success(reject)

        {

            if (reject.returnValue != null)

            {

                PrimaryControl.getAttribute("new_rejectreason").setValue(reject.returnValue);

             PrimaryControl.getAttribute("statecode").setValue(2); //In case entity statecode(optionset value) is the schema name of status.here 2 means cancelled .

                PrimaryControl.data.save();

            }

           

        },

        function error(e) {

            Xrm.Navigation.openAlertDialog("e.Message");

        }

    );

}

Go to solution and choose web Resource à click on Newà

Name & Display name: Enter Name (User defined)

choose type as Script(Javascript)

 

 


Click on Text editor and paste java script code here


Click on Ok and Publish.

Output:

Whenever you ‘re click on Reject button One popup will open

Here enter any information then click on submit

If you click on the submit that information is updated into Reject Reason field


If you click on the submit that information is updated into Reject Reason field

And Total case form is converted into Read-only format.

 


 

 

with out using Html code:

function popup(primary Control) {

    var form Context = primary Control;

    var txt;

    var rejectReason = prompt("Please enter your reason for Rejection:");

    if (rejectReason == null || rejectReason == "") {

        txt = " ";

    else {

        txt = rejectReason;

    }

    formContext.getAttribute("effi_rejectreason").setValue(txt);

}

For Read only:

function readOnly(primaryControl)

{

    var formContext = primaryControl;

    var formControls = formContext.ui.controls;

    formControls.forEach(control =>

    {

        if (control.getName() != "" && control.getName != null)

        {

            control.setDisabled(true);

        }                          

    });

}

Click on button command




After clicking on button command then below window will opened

Here click on Action and add

Library: Enter web Resource Name and click on search button

Function Name: Enter java script function name here.

Click on Add Parameter and choose Primary control

After filling all those details click on Publish


 

When you click on the reject button then one popup will opened with empty text field .

In this text box enter your info and click on ok

Then your info will reflect in to Reject Reason field and form will converts into Read only format.

 


 

Comments

Popular posts from this blog

SSRS User Story-7: Create a SSRS report group by Case, retrieve all work orders and make work orders as sub group, retrieve all bookable resource bookings based on work order. If booking is completed then show the row color as green.

SSRS User Story-6: Prepare a SSRS report on the birthday, In First part, group by with date of birth. In second report, prepare the wishes card with individual students.

SSRS User Story 2: Generate a report on individual student, if I click on the payment details report in student record. It need to show all the transactions done in current year along with sum. (it should show for each student separately)