### Expected Installation Output Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/basic-operations-powershell Example output showing the expected versions for PowerShell and the Az module. ```PowerShell PowerShell Version: 7.4.0 PowerShell Az version: 11.1.0 ``` -------------------------------- ### Start the development server Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/quick-start-js-spa Command to initialize the local development environment and start the server. ```bash npm start ``` -------------------------------- ### Debug Output Example Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/implementing-controls-using-typescript Shows the expected console output when the control harness starts successfully. ```CLI > pcf-project@1.0.0 start > pcf-scripts start "watch" [2:09:10 PM] [start] [watch] Initializing... [2:09:10 PM] [start] [watch] Validating manifest... [2:09:10 PM] [start] [watch] Validating control... [2:09:11 PM] [start] [watch] Generating manifest types... [2:09:11 PM] [start] [watch] Generating design types... [2:09:11 PM] [start] [watch] Compiling and bundling control... [Webpack stats]: asset bundle.js 6.56 KiB [emitted] (name: main) ./LinearInputControl/index.ts 4.9 KiB [built] [code generated] webpack 5.75.0 compiled successfully in 2060 ms [2:09:13 PM] [start] [watch] Generating build outputs... [2:09:13 PM] [start] [watch] Starting control harness... Starting control harness... [Browsersync] Access URLs: ---------------------------- Local: http://localhost:8181 ---------------------------- [Browsersync] Serving files from: C:\repos\LinearInput\out\controls\LinearInputControl [Browsersync] Watching files... ``` -------------------------------- ### Install dependencies and initialize the code app Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/npm-quickstart Install the required CLI tools and project dependencies, then initialize the app configuration. ```bash npm install -g @microsoft/power-apps-cli npm install -g @microsoft/power-apps npm install ``` ```bash power-apps init ``` ```bash power-apps init --display-name "App From Scratch" --environment-id ``` -------------------------------- ### Install Dataverse SDK from Source Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/get-started Clones the repository and installs the SDK in editable mode. ```bash git clone cd PowerPlatform-DataverseClient-Python pip install -e . ``` -------------------------------- ### Install Solution and Create Account Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/functions-actions-client-side-javascript Retrieves a solution ID, installs a managed solution if necessary, and creates an account record. ```javascript // Try to retrieve the ID after installing the solution this.#isSystemAdminFunctionSolutionId = await this.#getIsSystemAdminFunctionSolutionId(); if (this.#isSystemAdminFunctionSolutionId) { this.#entityStore.push({ entitySetName: "solutions", id: this.#isSystemAdminFunctionSolutionId, entityName: "solution", name: "IsSystemAdmin Function", }); // Pause for 30 seconds to give time for the API to be available await new Promise(resolve => setTimeout(resolve, 30000)); this.#util.appendMessage( "Installed IsSystemAdminFunction solution and added it to the entity store:" ); } else { this.#util.showError( "Failed to install retrieve the ID of the IsSystemAdminFunction solution." ); } } else { this.#util.appendMessage( "IsSystemAdmin Function solution is already installed." ); } // Create account to share const accountToShare = { name: "Account to Share", }; try { const accountToShareId = await this.#client.Create( "accounts", accountToShare ); this.#entityStore.push({ entitySetName: "accounts", id: accountToShareId, entityName: "account", name: accountToShare.name, }); } catch (error) { this.#util.showError( "Couldn't create the account record for sharing:" + error.message ); } } ``` -------------------------------- ### Install sample data using SDK for .NET Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sample-data Uses the InstallSampleDataRequest class to trigger the installation of sample data via the IOrganizationService. ```C# static void InstallSampleData(IOrganizationService service) { var request = new InstallSampleDataRequest(); service.Execute(request); } ``` -------------------------------- ### Install dependencies and initialize app Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/create-an-app-from-scratch Install required npm packages and initialize the project as a Power Apps code app. ```bash npm install pac code init --displayname "App From Scratch" ``` -------------------------------- ### Install code apps preview plugin Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/quickstart-github-copilot Install the specific code apps preview plugin from the added marketplace. ```bash /plugin install code-apps-preview@power-platform-skills ``` -------------------------------- ### Install AsyncDataverseClient Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/async-client Command to install the asynchronous client package via pip. ```bash pip install "PowerPlatform-Dataverse-Client[async]" ``` -------------------------------- ### Console Output Example Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-metadata-operations-sample Example output showing verification of specific entities in the returned list. ```text Contact is in the list of potential tables for N:N. sample_BankAccount is in the list of potential tables for N:N. ``` -------------------------------- ### Install React and Fluent UI dependencies Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/connect-to-azure-sql Install the required versions of React and the Fluent UI components library. ```bash npm install react@^18.0.0 react-dom@^18.0.0 @types/react@^18.0.0 @types/react-dom@^18.0.0 npm install @fluentui/react-components ``` -------------------------------- ### Install SDK with Claude Skills Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sdk-python/get-started Installs the SDK package and enables the Claude development skills. ```bash pip install PowerPlatform-Dataverse-Client && dataverse-install-claude-skill ``` -------------------------------- ### Install project dependencies Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/tutorial-create-canvas-dataset-component Commands to install project modules and UI framework dependencies. ```CLI npm install ``` ```PowerShell npm install react react-dom @fluentui/react ``` -------------------------------- ### Install component dependencies Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/tutorial-create-model-driven-app-dataset-component Run this command in the terminal within the project folder to install necessary dependencies. ```PowerShell npm install ``` -------------------------------- ### Simple Paging FetchXML Examples Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/page-results Examples demonstrating how to request specific pages of data by incrementing the page attribute in the fetch element. ```XML ``` ```XML ``` -------------------------------- ### Complete batch request example Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/execute-batch-operations-using-web-api A full example demonstrating multiple POST operations to create records and a GET operation to retrieve them within a single batch. ```http POST [Organization Uri]/api/data/v9.2/$batch HTTP/1.1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json Content-Type: multipart/mixed; boundary="batch_80dd1615-2a10-428a-bb6f-0e559792721f" --batch_80dd1615-2a10-428a-bb6f-0e559792721f Content-Type: application/http Content-Transfer-Encoding: binary POST /api/data/v9.2/tasks HTTP/1.1 Content-Type: application/json; type=entry { "subject": "Task 1 in batch", "regardingobjectid_account_task@odata.bind": "accounts(00000000-0000-0000-0000-000000000001)" } --batch_80dd1615-2a10-428a-bb6f-0e559792721f Content-Type: application/http Content-Transfer-Encoding: binary POST /api/data/v9.2/tasks HTTP/1.1 Content-Type: application/json; type=entry { "subject": "Task 2 in batch", "regardingobjectid_account_task@odata.bind": "accounts(00000000-0000-0000-0000-000000000001)" } --batch_80dd1615-2a10-428a-bb6f-0e559792721f Content-Type: application/http Content-Transfer-Encoding: binary POST /api/data/v9.2/tasks HTTP/1.1 Content-Type: application/json; type=entry { "subject": "Task 3 in batch", "regardingobjectid_account_task@odata.bind": "accounts(00000000-0000-0000-0000-000000000001)" } --batch_80dd1615-2a10-428a-bb6f-0e559792721f Content-Type: application/http Content-Transfer-Encoding: binary GET /api/data/v9.2/accounts(00000000-0000-0000-0000-000000000001)/Account_Tasks?$select=subject HTTP/1.1 --batch_80dd1615-2a10-428a-bb6f-0e559792721f-- ``` -------------------------------- ### Example Relationship Metadata Response Source: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/troubleshoot-forms A sample JSON response showing the AssociatedMenuConfiguration object, including the IsCustomizable property. ```JSON { "@odata.context": "[Organization URI]/api/data/v9.2/$metadata#RelationshipDefinitions/Microsoft.Dynamics.CRM.OneToManyRelationshipMetadata(AssociatedMenuConfiguration)/$entity", "MetadataId": "2124b4bd-f013-df11-a16e-00155d7aa40d", "AssociatedMenuConfiguration": { "Behavior": "UseCollectionName", "Group": "Details", "Order": null, "IsCustomizable": false, "Icon": null, "ViewId": "00000000-0000-0000-0000-000000000000", "AvailableOffline": true, "MenuId": null, "QueryApi": null, "Label": { "LocalizedLabels": [], "UserLocalizedLabel": null } } } ``` -------------------------------- ### Download and launch the Plug-in Registration Tool Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/download-tools-nuget Downloads the specified version of the PRT and launches it, creating a start menu shortcut. ```bash > pac tool prt Installing 9.1.0.155 version of PRT.... Shortcut in start menu created for 'Plugin Registration Tool' Installation complete Launched PRT (9.1.0.155). ``` -------------------------------- ### GET [Organization Uri]/api/data/v9.2/accounts Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-query-data-sample Executes a saved query using its GUID. ```APIDOC ## GET [Organization Uri]/api/data/v9.2/accounts ### Description Executes a saved query by passing the savedQuery GUID as a parameter. ### Method GET ### Endpoint [Organization Uri]/api/data/v9.2/accounts ### Query Parameters - **savedQuery** (string) - Required - The GUID of the saved query to execute ### Response #### Success Response (200) - **value** (array) - The result set of the executed query ``` -------------------------------- ### Define Single Language Label in Form XML Source: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/troubleshoot-forms Example of a navigation bar item configuration containing only a US English label. ```xml </Titles> </NavBarByRelationshipItem> ``` -------------------------------- ### Define Multi-Language Labels in Form XML Source: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/troubleshoot-forms Example of a navigation bar item configuration updated to include both US English and German labels. ```xml <NavBarByRelationshipItem Id="navContacts" Area="Sales" Sequence="10064" RelationshipName="contact_customer_accounts" Show="true"> <Titles> <Title LCID="1033" Title="Contacts" /> <Title LCID="1031" Title="Kontakte" /> </Titles> </NavBarByRelationshipItem> ``` -------------------------------- ### FetchXML Paging Request Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/page-results Example of an HTTP GET request using FetchXML with paging parameters. ```HTTP GET [Organization Uri]/api/data/v9.2/contacts?fetchXml=%3Cfetch%20count%3D%273%27%20page%3D%275%27%20paging-cookie%3D%27%26lt%3Bcookie%20page%3D%224%22%26gt%3B%26lt%3Bfullname%20last%3D%22Maria%20Campbell%20%28sample%29%22%20first%3D%22Patrick%20Sands%20%28sample%29%22%20%2F%26gt%3B%26lt%3Bcontactid%20last%3D%22%7B74BF4D48-34CB-ED11-B596-0022481D68CD%7D%22%20first%3D%22%7B82BF4D48-34CB-ED11-B596-0022481D68CD%7D%22%20%2F%26gt%3B%26lt%3B%2Fcookie%26gt%3B%27%3E%0D%0A%3Centity%20name%3D%27contact%27%3E%0D%0A%3Cattribute%20name%3D%27fullname%27%2F%3E%0D%0A%3Cattribute%20name%3D%27jobtitle%27%2F%3E%0D%0A%3Cattribute%20name%3D%27annualincome%27%2F%3E%0D%0A%3Corder%20descending%3D%27true%27%20attribute%3D%27fullname%27%2F%3E%0D%0A%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E Prefer: odata.include-annotations="Microsoft.Dynamics.CRM.fetchxmlpagingcookie,Microsoft.Dynamics.CRM.morerecords" OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Install sample data using Web API Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sample-data Executes the InstallSampleData action via an HTTP POST request. ```HTTP POST [Organization URI]/api/data/v9.2/InstallSampleData HTTP/1.1 Accept: application/json Content-Type: application/json; charset=utf-8 OData-MaxVersion: 4.0 OData-Version: 4.0 ``` ```HTTP HTTP/1.1 204 No Content OData-Version: 4.0 ``` -------------------------------- ### FetchXML Paging Request Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/page-results Example of a GET request using FetchXML with page and count parameters. ```http GET [Organization Uri]/api/data/v9.2/contacts?fetchXml=%3Cfetch%20count%3D%273%27%20page%3D%271%27%3E%0D%0A%3Centity%20name%3D%27contact%27%3E%0D%0A%3Cattribute%20name%3D%27fullname%27%2F%3E%0D%0A%3Cattribute%20name%3D%27jobtitle%27%2F%3E%0D%0A%3Cattribute%20name%3D%27annualincome%27%2F%3E%0D%0A%3Corder%20descending%3D%27true%27%20attribute%3D%27fullname%27%2F%3E%0D%0A%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E&$count=true Prefer: odata.include-annotations="Microsoft.Dynamics.CRM.fetchxmlpagingcookie,Microsoft.Dynamics.CRM.morerecords" OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Retrieve contacts ordered by income and title Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/query-data-client-side-javascript Partial example showing the setup for ordering results. ```javascript async #retrieveContosoContactsOrderedByAnnualIncomeAndTitle() { const columns = ["fullname", "jobtitle", "annualincome"]; const filters = [ "contains(fullname,'(sample)')", "_parentcustomerid_value eq " + this.#contosoAccountId, ]; ``` -------------------------------- ### Test the app locally Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/npm-quickstart Start the local development server to preview the application. ```bash npm run dev ``` -------------------------------- ### GET [Organization Uri]/api/data/v9.2/contacts Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-query-data-sample Retrieves a list of contacts filtered by a specific user query GUID. ```APIDOC ## GET [Organization Uri]/api/data/v9.2/contacts ### Description Retrieves contact records based on a saved user query identified by a GUID. ### Method GET ### Endpoint [Organization Uri]/api/data/v9.2/contacts ### Parameters #### Query Parameters - **userQuery** (string) - Required - The GUID of the saved user query. ### Response #### Success Response (200) - **value** (array) - A list of contact objects containing details like fullname, contactid, jobtitle, and annualincome. #### Response Example { "value": [ { "fullname": "Jim Glynn (sample)", "contactid": "f36e86e2-a228-ed11-9db1-000d3a320482", "jobtitle": "Senior International Sales Manager", "annualincome": 81400.0 } ] } ``` -------------------------------- ### ExecuteCosmosSqlQuery Request Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/reference/executecosmossqlquery Example of an HTTP GET request to execute a Cosmos SQL query with named parameters. ```HTTP GET [Organization Uri]/api/data/v9.2/ExecuteCosmosSqlQuery(QueryText=@p1,EntityLogicalName=@p2,QueryParameters=@p3,PageSize=@p4,PartitionId=@p5)?@p1='select c.props.contoso_deviceid as deviceId, c.props.contoso_timestamp as timestamp, c.props.contoso_energyconsumption.power as power from c where c.props.contoso_sensortype=@sensortype and c.props.contoso_energyconsumption.power > @power' &@p2='contoso_sensordata' &@p3={"Keys":["@sensortype","@power"],"Values":[{"Type":"System.String","Value":"Humidity"},{"Type":"System.Int32","Value":"5"}]} &@p4=50 &@p5='Device-ABC-1234' MSCRM.SessionToken: 207:8#142792107#7=-1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Insert Sample Projects Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/connect-to-azure-sql Populates the Projects table with initial sample data. ```sql INSERT INTO [dbo].[Projects] ([Name], [Description], [StartDate], [EndDate], [Status], [Priority], [Budget], [ProjectManagerEmail], [CreatedBy]) VALUES ('Website Redesign', 'Complete redesign of company website with modern UI/UX', '2025-06-01', '2025-08-31', 'Active', 'High', 75000.00, 'sarah.johnson@company.com', 'admin@company.com'), ('Mobile App Development', 'Develop iOS and Android mobile application for customer portal', '2025-07-01', '2025-12-31', 'Planning', 'Critical', 150000.00, 'mike.chen@company.com', 'admin@company.com'), ('Database Migration', 'Migrate legacy database to cloud infrastructure', '2025-05-15', '2025-09-30', 'Active', 'Medium', 50000.00, 'lisa.williams@company.com', 'admin@company.com'); GO PRINT 'Projects-only database schema created successfully with sample data!'; ``` -------------------------------- ### ExecuteCosmosSqlQuery Paged Request Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/reference/executecosmossqlquery Example of an HTTP GET request using a PagingCookie to retrieve subsequent pages of results. ```HTTP GET [Organization Uri]/api/data/v9.2/ExecuteCosmosSqlQuery(QueryText=@p1,EntityLogicalName=@p2,QueryParameters=@p3,PageSize=@p4,PagingCookie=@p5,PartitionId=@p6)?@p1='select c.props.contoso_deviceid as deviceId, c.props.contoso_timestamp as timestamp, c.props.contoso_energyconsumption.power as power from c where c.props.contoso_sensortype=@sensortype and c.props.contoso_energyconsumption.power > @power' &@p2='contoso_sensordata' &@p3={"Keys":["@sensortype","@power"],"Values":[{"Type":"System.String","Value":"Humidity"},{"Type":"System.Int32","Value":"5"}]} &@p4=50 @p5='W3sidG9rZW4iOiIrUklEOn5DVm9OQUpJaWRuTjBJajRBQUFBd0R3PT0jUlQ6MSNUUkM6NTAjSVNWOjIjSUVPOjY1NTUxI1FDRjo4I0ZQQzpBWFFpUGdBQUFEQVBveUkrQUFBQU1BOD0iLCJyYW5nZSI6eyJtaW4iOiIxNDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCIsIm1heCI6IjE0ODAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIn19XQ==' &@p6='Device-ABC-1234' MSCRM.SessionToken: 207:8#142792107#7=-1 OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Configure Main Entry Point Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/connect-to-azure-sql Wraps the application with necessary providers including FluentProvider for UI styling. ```typescript import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' import './index.css' import PowerProvider from './PowerProvider.tsx' import { FluentProvider, webLightTheme } from '@fluentui/react-components' import ProjectsTable from './ProjectsTable.tsx' createRoot(document.getElementById('root')!).render( <StrictMode> <PowerProvider> <FluentProvider theme={webLightTheme}> <ProjectsTable /> </FluentProvider> </PowerProvider> </StrictMode>, ) ``` -------------------------------- ### GET request with lookup annotations Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/select-columns Example request retrieving account names and owner IDs with the required annotation preferences. ```http GET [Organization URI]/api/data/v9.2/accounts?$select=name,_ownerid_value&$top=2 Accept: application/json OData-MaxVersion: 4.0 OData-Version: 4.0 Prefer: odata.include-annotations="Microsoft.Dynamics.CRM.associatednavigationproperty,Microsoft.Dynamics.CRM.lookuplogicalname" ``` -------------------------------- ### Web API Request with FetchXML Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/select-columns Example HTTP GET request using FetchXML with aliases via the Web API. ```HTTP GET [Organization Uri]/api/data/v9.2/accounts?fetchXml=%3Cfetch%3E%0D%0A++%3Centity+name%3D%22account%22%3E%0D%0A++++%3Cattribute+name%3D%22accountclassificationcode%22+alias%3D%22code%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22createdby%22+alias%3D%22whocreated%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22createdon%22+alias%3D%22whencreated%22+%2F%3E%0D%0A++++%3Cattribute+name%3D%22name%22+alias%3D%22companyname%22+%2F%3E%0D%0A++%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E&$count=true Prefer: odata.include-annotations="*" OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Initialize a solution project Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/import-custom-controls Creates a new solution project for bundling code components. Publisher name and prefix must be unique to the environment. ```CLI pac solution init --publisher-name developer --publisher-prefix dev ``` -------------------------------- ### GET [ORGANIZATION URI]/api/data/v9.2/sample_examples Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/column-level-security Retrieves a collection of example entities with unmasked data by including the UnMaskedData query parameter. ```APIDOC ## GET [ORGANIZATION URI]/api/data/v9.2/sample_examples ### Description Retrieves a collection of sample_example records with specific columns, including sensitive data, ordered by name in descending order. The UnMaskedData parameter is used to request unmasked values. ### Method GET ### Endpoint [ORGANIZATION URI]/api/data/v9.2/sample_examples ### Parameters #### Query Parameters - **$select** (string) - Required - Comma-separated list of columns to retrieve. - **$orderby** (string) - Required - The sorting criteria for the results. - **UnMaskedData** (boolean) - Optional - Set to true to request unmasked values for columns where the user has permission. ### Request Example GET [ORGANIZATION URI]/api/data/v9.2/sample_examples?$select=sample_name,sample_email,sample_governmentid,sample_telephonenumber,sample_dateofbirth&$orderby=sample_name%20desc&UnMaskedData=true HTTP/1.1 Accept: application/json Authorization: Bearer [Redacted] Prefer: odata.include-annotations="*" OData-Version: 4.0 OData-MaxVersion: 4.0 ### Response #### Success Response (200) - **value** (array) - A collection of retrieved entity records. #### Response Example { "@odata.context": "[ORGANIZATION URI]/api/data/v9.2/$metadata#sample_examples(sample_name,sample_email,sample_governmentid,sample_telephonenumber,sample_dateofbirth)", "value": [ { "sample_email": "jaydenp@adatum.com", "sample_governmentid": "***-**-5353", "sample_dateofbirth": "3/25/1974", "sample_name": "Jayden Phillips", "sample_telephonenumber": "(736) 555-9012" } ] } ``` -------------------------------- ### FunctionsAndActions Class Implementation Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/functions-actions-client-side-javascript Defines the class structure for managing the sample, including initialization, setup, and solution installation logic. ```JavaScript import { Util } from "../scripts/Util.js"; import { DataverseWebAPI as dv } from "../scripts/DataverseWebAPI.js"; import { customizationFile } from "../solutions/IsSystemAdminFunction_1_0_0_0_managed.js"; export class FunctionsAndActions { /** * @type {dv.Client} * @private */ #client; // The DataverseWebAPIClient.Client instance #container; // The container element to display messages #entityStore = []; // Store for created records to delete at the end of the sample #util; // Util instance for utility functions #whoIAm; // The current user's information #isSystemAdminFunctionSolutionId = null; // ID of the SystemAdminFunction solution #name = "Functions and actions"; // Name of the sample // Constructor to initialize the client, container, and utility helper functions constructor(client, container) { this.#client = client; this.#container = container; this.#util = new Util(container); } // Public functions to set up, run, and clean up data created by the sample async SetUp() { // Clear the container this.#container.replaceChildren(); this.#util.appendMessage(this.#name + " sample started"); // Get the current user's information try { this.#whoIAm = await this.#client.WhoAmI(); const contosoConsulting = { accountcategorycode: 1, address1_addresstypecode: 3, address1_city: "Redmond", address1_country: "USA", address1_line1: "123 Maple St.", address1_name: "Corporate Headquarters", address1_postalcode: "98000", address1_shippingmethodcode: 4, address1_stateorprovince: "WA", address1_telephone1: "555-1234", customertypecode: 3, description: "Contoso is a business consulting company.", emailaddress1: "info@contoso.com", industrycode: 7, name: "Contoso Consulting", numberofemployees: 150, ownershipcode: 2, preferredcontactmethodcode: 2, telephone1: "(425) 555-1234", }; const contosoConsultingId = await this.#client.Create( "accounts", contosoConsulting ); this.#entityStore.push({ entitySetName: "accounts", id: contosoConsultingId, entityName: "account", name: contosoConsulting.name, }); } catch (error) { this.#util.showError(error.message); } this.#isSystemAdminFunctionSolutionId = await this.#getIsSystemAdminFunctionSolutionId(); if (!this.#isSystemAdminFunctionSolutionId) { this.#util.appendMessage( "IsSystemAdmin Function solution is not installed. Installing it now... " ); // Install the IsSystemAdmin Function solution await this.#installIsSystemAdminFunctionSolution(); ``` -------------------------------- ### Build the solution project Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/import-custom-controls Commands to build the solution project and generate the zip file. Use /restore for the initial build. ```CLI msbuild /t:restore ``` ```CLI msbuild ``` ```CLI dotnet build ``` -------------------------------- ### Initialize component project Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/implementing-controls-using-typescript Run this command to scaffold a new component project with the specified namespace, name, and template. ```CLI pac pcf init --namespace SampleNamespace --name LinearInputControl --template field --run-npm-install ``` -------------------------------- ### GET /systemusers({id})/Microsoft.Dynamics.CRM.RetrievePrincipalAccess Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/use-web-api-functions Example of calling a Web API function that requires a record reference using the @odata.id annotation. ```APIDOC ## GET /systemusers({id})/Microsoft.Dynamics.CRM.RetrievePrincipalAccess ### Description Retrieves the access rights for a specific principal on a target record. This example demonstrates passing a record reference to the function using the @odata.id annotation. ### Method GET ### Endpoint /systemusers({id})/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@tid) ### Parameters #### Query Parameters - **@tid** (string) - Required - The @odata.id annotation specifying the target record, e.g., {'@odata.id':'contacts(aaaabbbb-0000-cccc-1111-dddd2222eeee)'} ### Request Example GET /systemusers(af9b3cf6-f654-4cd9-97a6-cf9526662797)/Microsoft.Dynamics.CRM.RetrievePrincipalAccess(Target=@tid)?@tid={'@odata.id':'contacts(aaaabbbb-0000-cccc-1111-dddd2222eeee)'} ``` -------------------------------- ### GET /GetTimeZoneCodeByLocalizedName Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/use-web-api-functions Example of invoking a Web API function using parameter aliases to safely pass string and numeric parameters. ```APIDOC ## GET /GetTimeZoneCodeByLocalizedName ### Description Retrieves the time zone code based on the provided localized name and locale ID. ### Method GET ### Endpoint /GetTimeZoneCodeByLocalizedName(LocalizedStandardName=@p1,LocaleId=@p2)?@p1='Pacific Standard Time'&@p2=1033 ### Parameters #### Query Parameters - **@p1** (string) - Required - The localized standard name of the time zone. - **@p2** (integer) - Required - The locale ID. ``` -------------------------------- ### Initialize the project Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/npm-quickstart Use degit to scaffold a new project from the official Vite template and navigate into the directory. ```bash npx degit github:microsoft/PowerAppsCodeApps/templates/vite my-app cd my-app ``` -------------------------------- ### Limit and Count Results Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/query-data-client-side-javascript Examples for limiting the number of returned records, getting a collection count, and retrieving a count of filtered results. ```javascript // Top results async #getTop5Contacts() { const columns = ["fullname", "jobtitle", "annualincome"]; const filters = [ "contains(fullname,'(sample)')", "_parentcustomerid_value eq " + this.#contosoAccountId, ]; const parameters = [ "$select=" + columns.join(","), "$filter=" + filters.join(" and "), "$top=5", ]; const query = parameters.join("&"); try { const contacts = await this.#client.RetrieveMultiple("contacts", query); this.#util.appendMessage("<strong>Top 5 contacts:</strong>"); this.#util.appendMessage("<pre>contacts?" + query + "</pre>"); const table = this.#util.createListTable(contacts, columns); this.#container.appendChild(table); } catch (e) { this.#util.showError("Failed to retrieve top 5 contacts."); throw e; } } ``` ```javascript // Collection count async #getContactCount() { try { const number = await this.#client.GetCollectionCount( "accounts(" + this.#contosoAccountId + ")/contact_customer_accounts" ); this.#util.appendMessage( `<strong>Contoso contact count: ${number}</strong>` ); } catch (e) { this.#util.showError("Failed to retrieve contact count."); throw e; } } ``` ```javascript // Result count async #getCountOfFilteredCollection() { const columns = ["fullname", "jobtitle", "annualincome"]; const OrFilters = [ "contains(jobtitle, 'senior')", "contains(jobtitle, 'manager')", ]; const filters = [ "contains(fullname,'(sample)')", "(" + OrFilters.join(" or ") + ")", "annualincome gt 50000", "_parentcustomerid_value eq " + this.#contosoAccountId, ]; const parameters = [ "$select=" + columns.join(","), "$filter=" + filters.join(" and "), "$count=true", ]; const query = parameters.join("&"); try { const contacts = await this.#client.RetrieveMultiple("contacts", query); this.#util.appendMessage( `<strong>Contact result count: ${contacts["@odata.count"]}</strong>` ); this.#util.appendMessage("<pre>contacts?" + query + "</pre>"); } catch (e) { this.#util.showError("Failed to retrieve contact count."); throw e; } } ``` -------------------------------- ### Run app locally Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/create-an-app-from-scratch Start the development server to test the application locally. ```bash npm run dev ``` -------------------------------- ### OData Query Options Usage Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/overview Examples demonstrating how to use OData query options with and without parameter aliases in a GET request. ```APIDOC ## GET [Organization URI]/api/data/v9.2/accounts ### Description Retrieves a collection of accounts using OData query options to filter, select, and order the results. ### Method GET ### Endpoint [Organization URI]/api/data/v9.2/accounts ### Query Parameters - **$select** (string) - Optional - Request a specific set of properties. - **$expand** (string) - Optional - Specify related resources to include. - **$orderby** (string) - Optional - Request resources in a particular order. - **$filter** (string) - Optional - Filter a collection of resources. - **$apply** (string) - Optional - Aggregate and group data. - **$top** (integer) - Optional - Specify the number of items to include. - **$count** (boolean) - Optional - Request a count of matching resources. ### Request Example (Without Aliases) GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue&$orderby=revenue asc,name desc&$filter=revenue ne null ### Request Example (With Parameter Aliases) GET [Organization URI]/api/data/v9.2/accounts?$select=name,revenue&$orderby=@p1 asc,@p2 desc&$filter=@p1 ne @p3&@p1=revenue&@p2=name ``` -------------------------------- ### ConditionalOperationsSample Class Implementation Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/samples/conditional-operations-client-side-javascript Defines the class structure for handling conditional GETs and optimistic concurrency, including setup and execution logic. ```javascript import { Util } from "../scripts/Util.js"; import { DataverseWebAPI as dv } from "../scripts/DataverseWebAPI.js"; export class ConditionalOperationsSample { /** * @type {dv.Client} * @private */ #client; // The DataverseWebAPIClient instance #container; // The container element to display messages #entityStore = []; // Store for created records to delete at the end of the sample #whoIAm; // Store for the current user's information #util; //Common functions for samples #name = "Conditional Operations"; // Constructor to initialize the client, container, and utility helper functions constructor(client, container) { this.#client = client; this.#container = container; this.#util = new Util(container); } // Public functions to set up, run, and clean up data created by the sample async SetUp() { // Clear the container this.#container.replaceChildren(); this.#util.appendMessage(this.#name + " sample started"); // Get the current user's information try { this.#whoIAm = await this.#client.WhoAmI(); } catch (error) { this.#util.showError(error.message); } } // Run the sample async Run() { try { //Section 0: Create sample record this.#util.appendMessage("<h2>0: Create sample record</h2>"); let accountRecord = await this.#createRetrieveAccount(); // Store the initial etag value for later use const initialETagValue = accountRecord["@odata.etag"]; //Section 1: Conditional GET this.#util.appendMessage("<h2>1: Conditional GET</h2>"); // Uses the client.Refresh method to refresh the account record with data from the server if changed accountRecord = await this.#conditionalGetUnChanged( accountRecord, "accountid" ); // Update the account record's telephone number await this.#updatePhoneNumber(accountRecord.accountid); // Uses the client.Refresh method to refresh the account record with changed data from the server accountRecord = await this.#conditionalGetChanged( accountRecord, "accountid" ); // Store the updated etag value for later use const updatedETagValue = accountRecord["@odata.etag"]; this.#util.appendMessage( `Original etag value: <code> ${initialETagValue}</code> Updated etag value: <code>${updatedETagValue}</code>` ); // Section 2: Optimistic concurrency on delete and update this.#util.appendMessage( "<h2>2: Optimistic concurrency on delete and update</h2>" ); // This should fail because the record has been changed this.#util.appendMessage( "Attempting to delete the account record with the <strong>original</strong> etag value: " + initialETagValue ); await this.#tryDelete(accountRecord.accountid, initialETagValue); // This should fail because the record has been changed this.#util.appendMessage( "Attempting to update the account record with the <strong>original</strong> etag value: " + initialETagValue ); await this.#tryUpdate(accountRecord.accountid, initialETagValue); // This should succeed because the etag value is current. this.#util.appendMessage( "Updating the account record with the <strong>updated</strong> etag value: " + updatedETagValue ); await this.#tryUpdate(accountRecord.accountid, updatedETagValue); // Show the record with updated values await this.#getRecord(accountRecord.accountid); } catch (error) { this.#util.showError(error.message); // Try to clean up even if an error occurs await this.CleanUp(); } } ``` -------------------------------- ### Open the Plug-in Registration tool via PAC CLI Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/create-custom-api-prt Use the Power Apps CLI to launch the PRT application. ```bash pac tool prt ``` -------------------------------- ### Build and deploy the app Source: https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/npm-quickstart Compile the project and publish it to the Power Apps environment. ```bash npm run build power-apps push ``` -------------------------------- ### URL with ribbon parameters Source: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/pass-parameters-url-by-using-ribbon An example of a URL containing appended query string parameters such as organization name, language codes, and record GUID. ```text https://myserver/mypage.aspx?orgname=AdventureWorksCycle&userlcid=1033&orglcid=1033&type=1&typename=account&id=%7BDBD5DBFB-0666-DC11-A5D9-0003FF9CE217%7D ``` -------------------------------- ### Initialize ESLint configuration Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/code-components-best-practices Run this command to start the ESLint configuration wizard for your project. ```shell npx eslint --init ``` -------------------------------- ### Retrieve contacts using userQuery Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-query-data-sample Use this HTTP GET request to fetch contact records associated with a specific user query GUID. ```HTTP GET [Organization Uri]/api/data/v9.2/contacts?userQuery=00aa00aa-bb11-cc22-dd33-44ee44ee44ee HTTP/1.1 Prefer: odata.maxpagesize=3; odata.include-annotations="*" OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Initialize Solution Project Source: https://learn.microsoft.com/en-us/power-apps/developer/component-framework/implementing-controls-using-typescript Initializes a new Dataverse solution project with specified publisher details. ```CLI pac solution init --publisher-name Samples --publisher-prefix samples ``` -------------------------------- ### HTTP Request for Paginated FetchXML Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/fetchxml/page-results An example HTTP GET request using the fetchXml parameter with URL-encoded content and required OData headers. ```http GET [Organization Uri]/api/data/v9.2/contacts?fetchXml=%3Cfetch%20count%3D%273%27%20page%3D%272%27%20paging-cookie%3D%27%26lt%3Bcookie%20page%3D%221%22%26gt%3B%26lt%3Bfullname%20last%3D%22Susanna%20Stubberod%20%28sample%29%22%20first%3D%22Yvonne%20McKay%20%28sample%29%22%20%2F%26gt%3B%26lt%3Bcontactid%20last%3D%22%7B70BF4D48-34CB-ED11-B596-0022481D68CD%7D%22%20first%3D%22%7B49B0BE2E-D01C-ED11-B83E-000D3A572421%7D%22%20%2F%26gt%3B%26lt%3B%2Fcookie%26gt%3B%27%3E%0D%0A%3Centity%20name%3D%27contact%27%3E%0D%0A%3Cattribute%20name%3D%27fullname%27%2F%3E%0D%0A%3Cattribute%20name%3D%27jobtitle%27%2F%3E%0D%0A%3Cattribute%20name%3D%27annualincome%27%2F%3E%0D%0A%3Corder%20descending%3D%27true%27%20attribute%3D%27fullname%27%2F%3E%0D%0A%3C%2Fentity%3E%0D%0A%3C%2Ffetch%3E Prefer: odata.include-annotations="Microsoft.Dynamics.CRM.fetchxmlpagingcookie,Microsoft.Dynamics.CRM.morerecords" OData-MaxVersion: 4.0 OData-Version: 4.0 If-None-Match: null Accept: application/json ``` -------------------------------- ### Retrieve Web API Service Document JSON Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/web-api-service-documents Example of the JSON response structure returned when performing a GET request on the Web API endpoint. ```json { "@odata.context": "https://yourorg.api.crm.dynamics.com/api/data/v9.2/$metadata", "value": [ { "name": "accountleadscollection", "kind": "EntitySet", "url": "accountleadscollection" }, { "name": "accounts", "kind": "EntitySet", "url": "accounts" }, ... ``` -------------------------------- ### POST InstallSampleData Source: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/sample-data Installs a pre-defined set of sample data into the organization. ```APIDOC ## POST [Organization URI]/api/data/v9.2/InstallSampleData ### Description Installs a pre-defined set of sample data. ### Method POST ### Endpoint [Organization URI]/api/data/v9.2/InstallSampleData ### Response #### Success Response (204) - No content returned. ```