
Announcements
Hello
I need to check values from a Dataverse form, based on existing Sharepoint subsites.
The user starts a precheck from the Dataverse form, a javascript should fire a Power Automate flow, and tell the user the precheck is done (or failed).
I followed these contents to write JS : softchief & How to build a Real-Time Power Automate Cloud Flow
The starting point component in the flow is 'when an http request is received', anthentication set to none, the generated url is pasted in the JS.
When passing this url in a browser, we have a result and we see in the flow execution history that the flow was fired.
When the JS is launched, messages are promted but the progress indicator never ends and there is nothing new in the flow execution history.
In the Power Platform Admin Center, the admin mode of the organisation is disabled.
Any idea ?
// mon commentaire
function runPowerAutoPreCheck(executionContext) {
alert("on manoeuvre +-+-+0001");
var formContext = executionContext.getFormContext();
var sousSiteGuid = formContext.data.entity.getId();
var ssType = formContext.getAttribute("jxsp_type").getValue();
//[...]
var ssEntreprise = formContext.getAttribute("jxsp_entreprise").getValue();
var ssBilan = formContext.getAttribute("jxsp_bilanexecution").getValue();
// stop if key fields do nt have data
if (ssEntreprise==null||1==2) {
Xrm.Utility.closeProgressIndicator();
return;
}
var PAParameters = {
"sousSiteGuid": sousSiteGuid,
"ssType": ssType,
//[..]
"ssEntreprise": ssEntreprise,
"ssBilan": ssBilan
}
alert("on manoeuvre 0002 /\ Entreprise =" +ssEntreprise+" json = "+JSON.stringify(PAParameters));
// url points to specific power automate
var url = "https://prod-34.westeurope.logic.azure.com:443/workflows/c8d...............a7/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=wQHtE...........ux-1WBE.........mEA";
var req = new XMLHttpRequest();
req.open("POST",url,true);
req.setRequestHeader('Content-Type','application/json');
//Xrm.Utility.alertDialog("Power Automate running");
req.send(JSON.stringify(PAParameters));
alert(" the rest is never shown ... ");
req.onreadystatechange = function () {
if (this.readyState ===4) {
req.onreadystatechange = null;
if (this.status ===200) {
var result = this.response;
// alert("" + result);
//formContext.data.refresh(false);
formContext.data.refresh(true);
Xrm.Utility.closeProgessIndicator();
}
else if (this.status === 400){
Xrm.Utility.closeProgessIndicator();
alert(this.statusText);
var result = this.response;
alert("Error : " + result);
}
}
};
Xrm.Utility.showProgressIndicator(' SharePoint Precheck en cours ');
//req.send(JSON.stringify(PAParameters));
//req.send();
}
Click on "F12" on your browser, open Dev tools and find out what's going wrong when you click the button, something on the network call is going wrong.
Having said that, there are other security issues, you've copied the URL in plain text which could be misused by an attacker.
Instead of "XmlHttpRequest" try to use "fetch".