3.On Click of approve button, approve status should be approved and send a mail to parents

 

User story: On Click of approve button, approve status should be approved and send a mail to parents?

Requirements: JavaScript and Workflow


1.      Create a custom Approve button by using XRM Tool box

2.      Create a field with Option set Datatype

3.      Provide a lookup field of contact entity with the name of Parent

4.      Create a Workflow to send an email to parent and copy the Workflow ID

5.      Write a JavaScript Function

·         If parent is not equal to null

·         Send an email to parent

6.      Call JavaScript function from approve button by using XRM Toolbox

 

Create a custom Approve button by using XRM Tool box, create a field with Option set Datatype and Provide a lookup field of contact entity with the name of Parent 


  Create a Workflow without triggering point to send an email to parent and copy the Workflow ID



Write a JavaScript Function and place it in Web resource 

function workflow(primarycontrol) {

    var formContext = primarycontrol;

    // To get current record guid

    var id = formContext.data.entity.getId().replace("{", "").replace("}", "");

    formContext.getAttribute("crb67_statuss").setValue(518320000);

    var WorkflowId = "09B3E720-E84E-448A-8D88-89F0FAEA4112";

 

    var entity =

    {

        "EntityId": id //Contact guid

    };

 

    var req = new XMLHttpRequest();

    req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/workflows(" + WorkflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow", 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.onreadystatechange = function () {

        if (this.readyState === 4) {

            req.onreadystatechange = null;

 

            if (this.status === 200) {

                Xrm.Utility.alertDialog("Email sent");

            } else {

                Xrm.Utility.alertDialog(this.statusText);

            }

        }

    };   

    req.send(JSON.stringify(entity));

}

Call JavaScript function from approve button by using XRM Toolbox



Out put:



 




Comments

Popular posts from this blog

2. 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

How to read JSON format data

Connect Dynamics 365 in Console Application using Application Registration and Application User