Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Email Triggering Three Times..

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have one process in this process record assigned to higher authority at that time email will trigger  i have written workflow.Some times its working fine only single mail trigger but some times it will triggering three mails same stage.How to avoid these problem i have facing past two weeks this problem.

Regards,

Ravi

*This post is locked for comments

  • RE: Email Triggering Three Times..

    I am delete old workflows and create new workflows but still i am facing this issues trigger mail three times some times..

  • RE: Email Triggering Three Times..

    still i am facing this issues can any one find where i am struct.

  • RE: Email Triggering Three Times..

    Hello vemareddyravi,

    The issue here is that each time the field is changed the workflow will fire,

    if you only want the workflow to fire once I would suggest adding a flag to the entity 'email created', at the last step of the workflow set 'email created' to yes.

    also add a check if it is set to 'no' before creating the email.

    this will ensure that the email will only fire the first time the field is changed.

    Regards,

      David Levins

  • RE: Email Triggering Three Times..

    My process is working fine enable buttons and disable buttons assign record to another users but some times email triggering three times that is problem.

  • RE: Email Triggering Three Times..
    function CheckUserRole() {
        debugger;
        var currentUserRoles = Xrm.Page.context.getUserRoles();
        for (var i = 0; i < currentUserRoles.length; i++) {
            var userRoleId = currentUserRoles[i];
            userRoleName = GetRoleName(userRoleId);
            return userRoleName;
        }
        return false;
    }
    
    function GetRoleName(roleId) {
        debugger;
    
        var roleName = null;
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/roles(" + roleId + ")?$select=name", false);
        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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function () {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(this.response);
                    roleName = result["name"];
    
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
    
        return roleName;
    }
    function submitForApproval() {
        debugger;
        var status = Xrm.Page.getAttribute("pcl_status_expensemanagement");
    
        var userRoleName = CheckUserRole();
        if (Xrm.Page.getAttribute("pcl_expensesubmit").getValue() == 0) {
    
            if (userRoleName == "Technical Officer") {
                Xrm.Utility.confirmDialog("Do you want to submit the record to Reporting Manager for approval? If Yes, then Please click on Ok.", function () {
    				Xrm.Page.getAttribute("pcl_reviewvp").setValue(false);
    				Xrm.Page.getAttribute("pcl_reviewfinance").setValue(false);
    				Xrm.Page.getAttribute("pcl_reviewreporting").setValue(false);
                   // Xrm.Utility.alertDialog("Record has been assigned to Reporting Manager for approval");
    				Xrm.Page.getAttribute("pcl_expensesubmit").setValue(true);
                    status.setValue(0);
    				status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_expensesubmit").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else {
                Xrm.Utility.alertDialog("Current user doesn't have sufficient privileges to Submit the record.");
            }
    
        }
        
        else {
            Xrm.Utility.alertDialog("Message: Record is already submitted.");
        }
    
    }
    function Approved() {
    
        debugger;
        var status = Xrm.Page.getAttribute("pcl_status_expensemanagement");
        var userRoleName = CheckUserRole();
        if (Xrm.Page.getAttribute("pcl_reportingapproval").getValue() == 0 || Xrm.Page.getAttribute("pcl_vpapproval_expns").getValue() == 0 || Xrm.Page.getAttribute("pcl_financeapproval").getValue() == 0 || Xrm.Page.getAttribute("pcl_rejectreporting").getValue() == 1 || Xrm.Page.getAttribute("pcl_rejectvp").getValue() == 1 || Xrm.Page.getAttribute("pcl_rejectfinance").getValue() == 1) {
            if (userRoleName == "Dy Manager Marketing" || userRoleName == "Manager Marketing") {
                Xrm.Utility.confirmDialog("Do you want to assign the record to Regional V.P for approval? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_approvedby");
                    setLookupNull("pcl_rejectedby");
    
                    //Xrm.Utility.alertDialog("Record has been assigned to Regional Head for approval");
    				
                    Xrm.Page.getAttribute("pcl_reportingapproval").setValue(true);
                    status.setValue(1);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_reportingapproval").setValue(false);
                    //status.setValue(null);
    
                });
    
    
            }
            else if (userRoleName == "Vice President") {
                Xrm.Utility.confirmDialog("Do you want to assign the record to Finance Officer for approval? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_approvedby");
                    setLookupNull("pcl_rejectedby");
                    //Xrm.Utility.alertDialog("Record has been assigned to Sales Account for approval");
                    Xrm.Page.getAttribute("pcl_vpapproval_expns").setValue(true);
                    status.setValue(1);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_vpapproval_expns").setValue(false);
                    //status.setValue(null);
    
                });
    
            }
            else if (userRoleName == "Finance Officer") {
                Xrm.Utility.confirmDialog("Do you want to approve the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_approvedby");
                    setLookupNull("pcl_rejectedby");               
                    //Xrm.Utility.alertDialog("Record has been approved by the Sales Account");
    				Xrm.Page.getAttribute("pcl_financeapproval").setValue(true);
                    status.setValue(1);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
    
    
                    //lock all fields.
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(true);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_financeapproval").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else {
                Xrm.Utility.alertDialog("Current user doesn't have sufficient privileges to Approve the record.");
            }
        }
        else {
            Xrm.Utility.alertDialog("Message: Record is already approved.");
        }
    }
    
    function rejected() {
        var status = Xrm.Page.getAttribute("pcl_status_expensemanagement");
        var userRoleName = CheckUserRole();
        if (Xrm.Page.getAttribute("pcl_reportingapproval").getValue() == 0 || Xrm.Page.getAttribute("pcl_vpapproval_expns").getValue() == 0 || Xrm.Page.getAttribute("pcl_financeapproval").getValue() == 0 || Xrm.Page.getAttribute("pcl_rejectreporting").getValue() == 0 || Xrm.Page.getAttribute("pcl_rejectvp").getValue() == 0 || Xrm.Page.getAttribute("pcl_rejectfinance").getValue() == 0) {
    
            if (userRoleName == "Dy Manager Marketing" || userRoleName == "Manager Marketing") {
                Xrm.Utility.confirmDialog("Do you want to reject the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_rejectedby");
                    setLookupNull("pcl_approvedby");				               
                    //Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for rejected");
    				Xrm.Page.getAttribute("pcl_rejectreporting").setValue(true);
                    status.setValue(2);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
    				
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_rejectreporting").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else if (userRoleName == "Vice President") {
                Xrm.Utility.confirmDialog("Do you want to reject the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_rejectedby");
                    setLookupNull("pcl_approvedby");               
                    //Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for rejected");
    				Xrm.Page.getAttribute("pcl_rejectvp").setValue(true);
                    status.setValue(2);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_rejectvp").setValue(false);
                    //status.setValue(null);
    
                });
    
            } else if (userRoleName == "Finance Officer") {
                Xrm.Utility.confirmDialog("Do you want to reject the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_rejectedby");
                    setLookupNull("pcl_approvedby");				                
                    //Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for rejected");
    				Xrm.Page.getAttribute("pcl_rejectfinance").setValue(true);
                    status.setValue(2);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_rejectfinance").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else {
                Xrm.Utility.alertDialog("Current user doesn't have sufficient privileges to Reject the record.");
                Xrm.Page.getAttribute("pcl_rejectedremarks").setRequiredLevel(none);
            }
        }
        else {
            Xrm.Utility.alertDialog("Message: Record is already rejected.");
        }
    
    }
    
    function SaveAndRefresh() {
        try {
            setTimeout(function () {
                var id = Xrm.Page.data.entity.getId();
                Xrm.Page.data.save();
                Xrm.Utility.openEntityForm("pcl_expensemanagement", id);
    
            }, 1000);
        }
        catch (e) {
            Xrm.Utility.alertDialog("Error: " + (e.message || e.description));
        }
    }
    function local_setCode() {
        setEmpCode("pcl_local_expenseid", "pcl_name");
    }
    function outstation_setCode() {
        setEmpCode("pcl_outstation_expenseid", "pcl_name");
    }
    
    function setEmpCode(fieldSchema, targetFieldSchema) {
        var selectedText = Xrm.Page.getAttribute(fieldSchema);
        if (selectedText != null) {
            var selectedTextValue = selectedText.getValue();
            if (selectedTextValue != null) {
                var Name = selectedTextValue[0].name;
                Xrm.Page.getAttribute(targetFieldSchema).setValue(Name);
            }
        }
    }
    // Functionality  :  To Hide and Show the Grids
    
    function hideGrids() {
        var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
        if (isCrmForMobile) {
            if (Xrm.Page.getAttribute("pcl_travelplantype") != undefined && Xrm.Page.getAttribute("pcl_travelplantype").getValue() != null) {
                var travelplanstage = Xrm.Page.getAttribute("pcl_travelplantype").getValue();
                if (travelplanstage == 0) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(false);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(false);
                }
                var travelplanstage = Xrm.Page.getAttribute("pcl_travelplantype").getValue();
                if (travelplanstage == 1) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(true);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(false);
                }
                var travelplanstage = Xrm.Page.getAttribute("pcl_travelplantype").getValue();
                if (travelplanstage == 2) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(false);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(true);
                }
    
            }
        }
        else if (!isCrmForMobile) {
    
            if (Xrm.Page.getAttribute("pcl_travelplantype") != undefined && Xrm.Page.getAttribute("pcl_travelplantype").getValue() != null) {
                var travelplanstage = Xrm.Page.getAttribute("pcl_travelplantype").getValue();
                if (travelplanstage == 0) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(false);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(false);
                }
                else if (travelplanstage == 1) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(true);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(false);
                }
                else if (travelplanstage == 2) {
                    Xrm.Page.ui.tabs.get("domestic_tab").setVisible(false);
                    Xrm.Page.ui.tabs.get("outstation_tab").setVisible(true);
                }
    
            }
        }
    }
    function setLookupField(fieldSchema, targetFieldSchema) {
        var selectedText = Xrm.Page.getAttribute(fieldSchema);
        if (selectedText != null) {
            var selectedTextValue = selectedText.getValue();
            if (selectedTextValue != null) {
                var Id = selectedTextValue[0].id;
                var Name = selectedTextValue[0].name;
                var Type = selectedTextValue[0].entityType;
                Xrm.Page.getAttribute(targetFieldSchema).setValue(selectedTextValue);
                Xrm.Page.getAttribute(targetFieldSchema).setSubmitMode("always");
            }
    
        }
    }
    
    function setLookupNull(lookupAttribute) {
        var lookupObject = Xrm.Page.getAttribute(lookupAttribute);
        if (lookupObject != null) {
            Xrm.Page.getAttribute(lookupAttribute).setValue(null);
        }
    }
    
    
    ///Functional review to salesperson
    
    function Review() {
        var status = Xrm.Page.getAttribute("pcl_status_expensemanagement");
        var userRoleName = CheckUserRole();
        if (Xrm.Page.getAttribute("pcl_reportingapproval").getValue() == 0 || Xrm.Page.getAttribute("pcl_vpapproval_expns").getValue() == 0 || Xrm.Page.getAttribute("pcl_reviewreporting").getValue() == 0 || Xrm.Page.getAttribute("pcl_reviewvp").getValue() == 0 || Xrm.Page.getAttribute("pcl_reviewfinance").getValue() == 0 || Xrm.Page.getAttribute("pcl_financeapproval").getValue() == 0) {
    
            if (userRoleName == "Dy Manager Marketing" || userRoleName == "Manager Marketing") {
                Xrm.Utility.confirmDialog("Do you want to review the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_reviewedbyid");
                    setLookupNull("pcl_approvedby");				
    				Xrm.Page.getAttribute("pcl_reportingapproval").setValue(false);
    				Xrm.Page.getAttribute("pcl_expensesubmit").setValue(false);
                    //Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for review");
    				Xrm.Page.getAttribute("pcl_reviewreporting").setValue(true);
                    status.setValue(4);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
    
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_reviewreporting").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else if (userRoleName == "Vice President") {
                Xrm.Utility.confirmDialog("Do you want to review the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_reviewedbyid");
                    setLookupNull("pcl_approvedby");
    				Xrm.Page.getAttribute("pcl_reportingapproval").setValue(false);
    				Xrm.Page.getAttribute("pcl_expensesubmit").setValue(false);
    				Xrm.Page.getAttribute("pcl_vpapproval_expns").setValue(false);
                    //Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for review");
    				Xrm.Page.getAttribute("pcl_reviewvp").setValue(true);
                    status.setValue(4);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
    
    
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_reviewvp").setValue(false);
                    //status.setValue(null);
    
                });
    
            } else if (userRoleName == "Finance Officer") {
                Xrm.Utility.confirmDialog("Do you want to review the record? If Yes, then Please click on Ok.", function () {
                    setLookupField("ownerid", "pcl_reviewedbyid");
                    setLookupNull("pcl_approvedby");
    				Xrm.Page.getAttribute("pcl_reportingapproval").setValue(false);
    				Xrm.Page.getAttribute("pcl_expensesubmit").setValue(false);
    				Xrm.Page.getAttribute("pcl_vpapproval_expns").setValue(false);
                    Xrm.Utility.alertDialog("Record has been assigned to Technical Officer for review");
    				Xrm.Page.getAttribute("pcl_reviewfinance").setValue(true);
                    status.setValue(4);
                    status.setSubmitMode("always");
                    Xrm.Page.data.entity.save("save");
                    Xrm.Page.ui.controls.forEach(function (control) {
                        if (control.setDisabled) {
                            control.setDisabled(false);
                        }
                    });
                    SaveAndRefresh();
                }, function () {
                    //Cancel button logic
                    Xrm.Page.getAttribute("pcl_reviewfinance").setValue(false);
                    //status.setValue(null);
    
                });
            }
            else {
                Xrm.Utility.alertDialog("Current user doesn't have sufficient privileges to Review the record.");
                Xrm.Page.getAttribute("pcl_rejectedremarks").setRequiredLevel(none);
            }
        }
        else {
            Xrm.Utility.alertDialog("Message: Record is already review.");
        }
    
    }
    
    ////Hide and Show Approve,Review,Reject Buttons on Expense Management
    function approveRejectReview() {
        debugger;
        //Lead Status
        var leadStatus = null;
        if (Xrm.Page.getAttribute("pcl_status_expensemanagement").getValue() != null && Xrm.Page.getAttribute("pcl_status_expensemanagement").getValue() != undefined) {
            leadStatus = Xrm.Page.getAttribute("pcl_status_expensemanagement").getValue();
        }
    
        //Current logged in user Id
        var contextUser = Xrm.Page.context.getUserId();
        var isQualifyingUser = false;
        //Finance approval
        var financeApproval = false;
        if (Xrm.Page.getAttribute("pcl_financeapproval").getValue() != null && Xrm.Page.getAttribute("pcl_financeapproval").getValue() != undefined) {
            financeApproval = Xrm.Page.getAttribute("pcl_financeapproval").getValue();
        }
        //Owner field
        var ownerName = null;
        if (Xrm.Page.getAttribute("ownerid").getValue() != null && Xrm.Page.getAttribute("ownerid").getValue() != undefined) {
            ownerName = Xrm.Page.getAttribute("ownerid").getValue()[0].id;
            if (ownerName == contextUser) {
                isQualifyingUser = true;
            }
        }
        var userRoleName = CheckUserRole();
        if (userRoleName == "Technical Officer") {
            if (leadStatus == null || isQualifyingUser || leadStatus == 0 || leadStatus == 2 || leadStatus == 4) {
                return false;
            }
            else {
                return true;
            }
        }
        else if (userRoleName == "Dy Manager Marketing") {
            if ((leadStatus == 1 || leadStatus == 2 || leadStatus == 4) && !isQualifyingUser) {
                return false;
            }
            else {
                return true;
            }
        }
        else if (userRoleName == "Vice President") {
            if ((leadStatus == 1 || leadStatus == 2 || leadStatus == 4) && !isQualifyingUser) {
                return false;
            }
            else {
                return true;
            }
        }
        else if (userRoleName == "Finance Officer") {
            if (financeApproval || leadStatus == 2 || leadStatus == 4) {
                return false;
            }
            else {
                return true;
            }
        }
    }
    

    Iam writing this code..

  • RE: Email Triggering Three Times..

    Capture.PNG-RJ.PNGCapture.PNG-RJ.PNG

    This is the workflow and result but iam facing some times not regular what is the problem..

  • ansrikanth Profile Picture
    ansrikanth 3,115 on at
    RE: Email Triggering Three Times..

    Not the screen shot of the Email, rather the screenshot of the WF. Also, the WF Executions screen shot :)

  • RE: Email Triggering Three Times..

    38807.Capture.PNG

  • Zohaib Uddin Khan Profile Picture
    Zohaib Uddin Khan 2,811 on at
    RE: Email Triggering Three Times..

    Share the snapshot of your workflow and check the history of the process also. Definitely, it is triggering thrice because of the way it was implemented.

  • RE: Email Triggering Three Times..

    on field change its working.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans