首页 > 解决方案 > 我可以从自定义 JavaSript 触发 Power Automate 工作流吗?

问题描述

如何从我的自定义 JavaScript 代码启动/触发任何流程?

我不是在询问按钮流程,也不是任何开箱即用的功能,我只是想从我的 JavaScript 代码触发我的流程

标签: javascriptpower-automate

解决方案


通过“请求 - 收到 HTTP 请求时”创建流触发器,您可以在TechNet wiki 页面中找到该脚本。

function StartMicrosoftFlowTriggerOperations() { 
    try { 
        var dataTemplate = "{\r\n    \"emailaddress\":\"{0}\",\r\n    \"emailSubject\": \"{1}\",\r\n    \"emailBody\": \"{2}\"\r\n}"; 
        var httpPostUrl = "<Supply with the HTTP POST Url>"; 
        //Call FormatRow function and replace with the values supplied in input controls. 
        dataTemplate = dataTemplate.FormatRow($("#txtEmailAddress").val(), $("#txtEmailSubject").val(), $("#txtEmailBody").val());
         var settings = { 
            "async": true, 
            "crossDomain": true, 
            "url": httpPostUrl, 
            "method": "POST", 
            "headers": { 
                "content-type": "application/json", 
                "cache-control": "no-cache" 
            }, 
            "processData": false, 
            "data": dataTemplate 
        } 
        $.ajax(settings).done(function (response) { 
            console.log("Successfully triggered the Microsoft Flow. "); 
        }); 
    } 
    catch (e) { 
        console.log("Error occurred in StartMicrosoftFlowTriggerOperations " + e.message); 
    } 
}

推荐阅读