dynamics_generate_fetchxml
Generate FetchXML queries for Dynamics CRM by specifying entities, columns, filters, and joins to retrieve structured data efficiently.
Instructions
Gera FetchXML com base em parâmetros estruturados
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entityLogicalName | Yes | Entidade principal | |
| columns | Yes | Colunas a retornar | |
| filters | No | Filtros | |
| orders | No | ||
| linkedEntities | No | ||
| top | No |
Implementation Reference
- src/tools/schema/index.ts:606-658 (handler)The handler implementation for the `dynamics_generate_fetchxml` tool, which constructs a FetchXML string based on the provided schema parameters.
server.tool( "dynamics_generate_fetchxml", "Gera FetchXML com base em parâmetros estruturados", GenerateFetchXmlSchema.shape, async (params: z.infer<typeof GenerateFetchXmlSchema>) => { let fetchXml = `<fetch version="1.0" output-format="xml-platform" mapping="logical"`; if (params.top) fetchXml += ` top="${params.top}"`; fetchXml += `>\n <entity name="${params.entityLogicalName}">\n`; for (const col of params.columns) { fetchXml += ` <attribute name="${col}" />\n`; } if (params.orders) { for (const order of params.orders) { fetchXml += ` <order attribute="${order.attribute}" descending="${order.descending}" />\n`; } } if (params.filters && params.filters.length > 0) { fetchXml += ` <filter type="and">\n`; for (const f of params.filters) { if (f.value) { fetchXml += ` <condition attribute="${f.attribute}" operator="${f.operator}" value="${f.value}" />\n`; } else { fetchXml += ` <condition attribute="${f.attribute}" operator="${f.operator}" />\n`; } } fetchXml += ` </filter>\n`; } if (params.linkedEntities) { for (const le of params.linkedEntities) { fetchXml += ` <link-entity name="${le.name}" from="${le.from}" to="${le.to}" alias="${le.alias}" link-type="${le.linkType}">\n`; for (const col of le.columns) { fetchXml += ` <attribute name="${col}" />\n`; } fetchXml += ` </link-entity>\n`; } } fetchXml += ` </entity>\n</fetch>`; return { content: [ { type: "text" as const, text: `FetchXML gerado:\n\n\`\`\`xml\n${fetchXml}\n\`\`\``, }, ], }; } ); - src/tools/schema/index.ts:106-127 (schema)The input validation schema (`GenerateFetchXmlSchema`) for the `dynamics_generate_fetchxml` tool.
export const GenerateFetchXmlSchema = z.object({ entityLogicalName: z.string().describe("Entidade principal"), columns: z.array(z.string()).describe("Colunas a retornar"), filters: z.array(z.object({ attribute: z.string(), operator: z.string(), value: z.string().optional(), })).optional().describe("Filtros"), orders: z.array(z.object({ attribute: z.string(), descending: z.boolean().default(false), })).optional(), linkedEntities: z.array(z.object({ name: z.string(), from: z.string(), to: z.string(), alias: z.string(), columns: z.array(z.string()), linkType: z.enum(["inner", "outer"]).default("outer"), })).optional(), top: z.number().optional(), });