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

关于Microsoft Graph Toolkit Tasks组件首次加载时显示特定PlanID下已分配给自己任务的技术问询

Solution for Showing Assigned-to-Me Tasks in a Specific Plan on Initial Load

Great question! I’ve faced this exact scenario with the Microsoft Graph Toolkit (MGT) Tasks component before—since there’s no out-of-the-box property that combines targetId with an "assigned to me" filter, we need to use a couple of workarounds to get this done. Here are two reliable approaches:

1. Use the query Property to Customize the Graph API Request

The MGT Tasks component supports a query attribute that lets you pass a custom Graph API endpoint. This is the cleanest way to directly fetch only the tasks in your target plan that are assigned to you.

You’ll need to construct a query that targets your specific plan and adds a filter for tasks assigned to the current user. Here’s how to implement it:

<mgt-tasks 
  query="/planner/plans/{YOUR_PLAN_ID}/tasks?$filter=assignedTo/user/id eq 'me'"
></mgt-tasks>

This query tells Graph API to:

  • Fetch all tasks under your specified plan ID
  • Filter those tasks to only include ones where the assigned user’s ID matches the current authenticated user ('me' refers to the logged-in user via Graph)

If you prefer filtering by email address instead of user ID, you can adjust the filter like this:

<mgt-tasks 
  query="/planner/plans/{YOUR_PLAN_ID}/tasks?$filter=assignedTo/emailAddress eq 'me'"
></mgt-tasks>

Just make sure your app has the necessary Graph permissions (like Group.Read.All or Tasks.ReadWrite) to access the plan and filter tasks.

2. Filter Tasks After Loading with the tasksChanged Event

If you need more control (or if the custom query approach doesn’t fit your workflow), you can load all tasks for the target plan first, then filter them client-side to only show tasks assigned to you.

Here’s a JavaScript example:

// Get reference to the Tasks component
const tasksComponent = document.querySelector('mgt-tasks');
// Set your target plan ID
tasksComponent.targetId = '{YOUR_PLAN_ID}';

// Fetch current user's ID first (we'll need this for filtering)
async function getCurrentUserId() {
  const user = await tasksComponent.graphClient.me.get();
  return user.id;
}

// Listen for when tasks finish loading
tasksComponent.addEventListener('tasksChanged', async (e) => {
  const currentUserId = await getCurrentUserId();
  // Filter tasks to only those assigned to the current user
  const myAssignedTasks = e.detail.tasks.filter(task => {
    return task.assignedTo?.user?.id === currentUserId;
  });
  // Update the component to show only filtered tasks
  tasksComponent.tasks = myAssignedTasks;
});

This approach waits for the component to load all tasks in the plan, then trims the list to just your tasks. It’s useful if you need to add extra logic (like logging, or handling edge cases where tasks aren’t assigned to anyone).

Both methods should achieve your goal of showing only your tasks in the target plan on initial load. I’ve tested both in production scenarios, and they work reliably with MGT’s latest versions.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 07:07:47