Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Commenting out alert breaks code

Posted on by 212

Hello, 

We are having an issue where we have created JavaScript to run a workflow through a function. We had created alerts throughout the code while writing and testing. Everything was working great and the workflows were being executed. However, when we commented out our alert, the execute workflow stopped working. Please help:

function RunWorkflow(workflowId, JobId) {
var clientUrl = "">http://ct-d365sb/CTi";
var data = {
"EntityId":JobId
};
try {
var req = new XMLHttpRequest();
req.open("POST", clientUrl + "/api/data/v9.0/workflows(" + workflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
//var result = JSON.parse(this.response);
} else {
var error = JSON.parse(this.response).error;
alert(error.message);
}
}
};
req.send(JSON.stringify(data));
alert(workflowId + " SENT " + JobId);

}

catch (e) {
throw (e);
}
}

Anyone have any suggestions? The alert causing the problem is the alert right below the "req.send(JSON.stringify(data));"

Thank you in advance! This has been driving us crazy for 2 days!

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Commenting out alert breaks code

    Hi,

    Replace alert with console log to see if you are still have issue.

    console.log(workflowId + "SENT" + JobId);

  • CarlosDuran Profile Picture
    CarlosDuran 5 on at
    RE: Commenting out alert breaks code

    Hi

    As a suggestion have you checked if you have values in the both variables.

    Best regards

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,188 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans