You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerApps中Chatbot连接报错求助:GenerateAnswer参数数量无效

Fixing the "Invalid number of arguments" Error in PowerApps QnA Maker Integration

Hey there, let's tackle that frustrating "Invalid number of arguments" error you're hitting when triggering the button's OnSelect event. The root issue is a mismatch in how you're calling the QnA Maker connector's GenerateAnswer function—let's break this down step by step.

First, Let's Recap Your Setup

Your screen OnStart code looks solid for initializing the chat:

ClearCollect(chat,{id:0,name:"EmployeeFaqBot",text:"Welcome " &User().FullName &" ! Enter your Query"})

The problem lies in how you're invoking OPMS_Service.GenerateAnswer in your button code.

Why Your Original Code Fails

Your initial button OnSelect code includes an extra, unnecessary parameter:

Collect(chat,{id:1,name:User().FullName,text:TextInput1.Text}); 
Collect(chat,{id:0,name:"EmployeeFaqBot",text:First(OPMS_Service.GenerateAnswer("a6*****7c","application/json",{question:TextInput1.Text}).answers).answer})

The QnA Maker connector's GenerateAnswer function only expects two required parameters:

  1. Your QnA Knowledge Base ID (the "a6*****7c" value you already have)
  2. A request object containing the question key

The "application/json" string you added is redundant—PowerApps handles the content type automatically for the connector, so passing it here causes the "invalid number of arguments" error.

The Corrected Button OnSelect Code

Replace your button code with this version, which removes the extra parameter and follows the correct function structure:

Collect(chat, {id: 1, name: User().FullName, text: TextInput1.Text});
Collect(chat, {id: 0, name: "EmployeeFaqBot", text: First(OPMS_Service.GenerateAnswer("a6*****7c", {question: TextInput1.Text}).answers).answer})

What Was Wrong With Your Other Attempts

Let's quickly go over why your alternate code snippets didn't work:

  • Attempt 1 (missing Knowledge Base ID): GenerateAnswer({question:TextInput1.Text}) omits the first required parameter (your KB ID), so the function doesn't know which QnA dataset to query.
  • Attempt 2 (swapped parameters): GenerateAnswer("application/json",{question:TextInput1.Text}) uses the content type string as the KB ID, which is an invalid value and mismatches the expected parameter type.
  • Attempt 3 (invalid object syntax): GenerateAnswer({"application/json",question:TextInput1.Text}) uses broken object syntax (you can't list values without keys) plus still includes the unnecessary content type.

Bonus: Add Robust Error Handling

To make your chat more user-friendly, wrap the bot response in an IfError block to handle cases where the QnA service might fail:

Collect(chat, {id: 1, name: User().FullName, text: TextInput1.Text});
IfError(
    Collect(chat, {id: 0, name: "EmployeeFaqBot", text: First(OPMS_Service.GenerateAnswer("a6*****7c", {question: TextInput1.Text}).answers).answer}),
    Collect(chat, {id: 0, name: "EmployeeFaqBot", text: "Sorry, I couldn't process your query right now. Please try again later."})
)

内容的提问来源于stack exchange,提问作者Jyoti Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:25:26