RE: Web resource button to trigger a Power Automate Flow
Hi Sam,
1. As following tutorial said:
https://carldesouza.com/how-to-use-formcontext-in-a-web-resource-in-dynamics-365-power-apps/
To use formContext in web resource, firstly we need to pass it from Form to our Web Resouce:
(Run form_onload function at OnLoad event of form.)
function form_onload(executionContext) {
var formContext = executionContext.getFormContext();
var wrControl = formContext.getControl("WebResource_MyWebResource");
if (wrControl) {
wrControl.getContentWindow().then(
function (contentWindow) {
contentWindow.setClientApiContext(formContext);
}
)
}
}
Secondly, in the web resource, we need to add an extra function setClientApiContext to set formContext as global variable on the web resource page.
function setClientApiContext(formContext) {
window._formContext = formContext;
}
2. Now in PostFlow function, the formContext can be used directly.
However, we should use formContext.data.entity.getId() to get entity GUID instead, because formContext.getAttribute() only works for attribute that has been added to Form.
var quote = _formContext.data.entity.getId().replace(/\{|\}/gi, "").toLowerCase();
Full code in script tag of your web resource:
function setClientApiContext(formContext) {
window._formContext = formContext;
}
function PostFlow() {
var quote = _formContext.data.entity.getId().replace(/\{|\}/gi, "").toLowerCase();
// Same to original
}
setClientApiContext function will be automatically loaded.
Regards,
Clofly