Showing posts with label Power Apps. Show all posts
Showing posts with label Power Apps. Show all posts

How to Search 2 Million Dataverse Records in a Canvas App Without Delegation Issues

How to let users search by multiple fields without hitting delegation limits or performance walls.

The problem

Your Dataverse table has two million rows. Users want one screen where they can search by reference number, status, date, customer name, and more.

It works perfectly in testing with 300 records. In production, results quietly go missing, and nobody gets an error.

This post explains why that happens and how to design the search so it never does.

First, what is delegation?

Delegation means Power Apps sends the query to the data source (Dataverse, SQL, SharePoint) to process, and only the matching rows come back. If a function can't be delegated, Power Apps downloads only the first 500 records (adjustable up to 2,000) and filters those locally.

The result is incomplete, and there is no error.

Delegable query

You search 2M records for Status = "Open" and 10,000 match. Dataverse does the filtering and returns all 10,000, page by page.

Non-delegable query

Power Apps checks only the first 500 to 2,000 rows and silently misses the rest. The user sees a short list and assumes it's complete.

How to spot it

A blue underline and a warning triangle appear in Studio on non-delegable formulas. Treat them as errors, not suggestions.

Delegable vs non-delegable by data source

Function / operatorDataverseSQL ServerSharePointExcel
Filter, LookUp✅✅✅⚠️ limited
=, <>, <, >, And, Or✅✅✅ (some column types restricted)⚠️
StartsWith✅✅✅❌
in (contains)✅❌❌❌
Search()✅ (with Dataverse search enabled)❌❌❌
Sort, SortByColumns✅✅✅⚠️
Sum, Average, Min, Max, CountRows✅ (with limits)✅❌❌
Left, Mid, Len, Lower on a column❌❌❌❌
ForAll, AddColumns, GroupBy, First, Last on source❌❌❌❌
Trust the warning, not the table

Support varies by connector and version, so always trust the delegation warning in Studio over any table, this one included. And Excel is not a real database. Don't use it for anything large.

The design principle

In a Canvas App, delegation is the first thing I design around. With 2M records, I never bring data into the app. I make sure every search runs on the server.
User inputfilters + Search button
→
Delegable formulaFilter / StartsWith / in
→
Dataversefilters on the server
→
Gallerysmall page of rows

Step 1: Use delegable building blocks

  • Filter with =, And, Or, and StartsWith on text
  • in or Search (with Dataverse search enabled) for "contains" matching
  • Choice, Lookup, Date and Number columns for filters instead of free text
  • LookUp for single records

Here is a multi-field search where every part is delegable. Each filter is skipped when its control is empty:

Power Fx · Gallery Items
Filter(
    Orders,
    IsBlank(txtRef.Text) || StartsWith(ReferenceNo, txtRef.Text),
    IsBlank(drpStatus.Selected.Value) || Status = drpStatus.Selected.Value,
    IsBlank(dpFrom.SelectedDate) || OrderDate >= dpFrom.SelectedDate
)

Step 2: Add methods that protect performance

Delegable formulas stop wrong results. These habits stop slow ones.

Most important
1. Make it selective
Require at least one filter or a minimum number of characters. Use a Search button (or DelayOutput on the text input) instead of querying on every keystroke. A blank search returning 2M rows is what kills performance.
Avoid
2. Don't collect the table
ClearCollect(colOrders, Orders) is capped at the row limit and slow.
Pattern
3. Search-key column
Keep one column that concatenates the searchable fields (via a calculated column or a flow). Run a single StartsWith or in on it instead of ORing five columns.
Pattern
4. Quick Find + Dataverse search
Put searchable columns in the Quick Find view and enable Dataverse search for a "Google-style" single search box.
Quick win
5. Pull only what you need
Use ShowColumns to limit columns, and show results in a gallery.
Fallback
6. Server-side logic
For complex logic, use a Dataverse view, a plug-in, a flow or a custom API. Power users can also get a model-driven app with Advanced Find.

Step 3: Verify it

  • No delegation warnings anywhere in Studio.
  • Power Apps Monitor shows one Dataverse call with a $filter and a small payload.
  • A test record located beyond row 2,000 is still found. This is the test that proves delegation is really working.
Why the third check matters

Non-delegable searches look fine on small test data. Only a record deliberately placed past the row limit will reveal that results are being cut off.

Interview answer

If you're asked this in an interview, here is the short version:

With a 2M-record table, delegation is the main concern, because non-delegable formulas only process the first 500 to 2,000 rows and silently return incomplete results. So I push all filtering to Dataverse using delegable functions like Filter, StartsWith, in and Choice or Lookup columns, and I avoid things like Left, Len, ForAll or collecting the whole table. To keep it fast, I require at least one filter or a minimum number of characters, trigger the search from a button, and use a concatenated search-key column or Dataverse search for a single search box. I validate with Monitor and by testing records beyond row 2,000.
The rule of thumb

Never bring the data to the app; send the question to the data. Filter on the server with delegable functions, force users to be selective, and prove it works with a record that sits beyond the row limit.

📘 How to Create a SharePoint Site – Step-by-Step Guide

Introduction to SharePoint | Power Platform Blog
SharePoint · Power Platform

Getting Started with
SharePoint Sites

Sites · Lists · Document Libraries · Power Platform Integration

Team Site Communication Site Power Apps Dynamics 365
SharePoint is a Microsoft platform used to store files, manage data, and help teams work together easily. If you are working with Power Platform or Dynamics 365, SharePoint is often used to store documents, manage lists, and share information across teams. This guide walks you through everything step by step.

What is a SharePoint Site?

A SharePoint site is like a workspace where you can store documents, manage data, share updates, and collaborate with your team. Think of it as a central hub that connects your files, your people, and your data — all in one place.

It is commonly used for document storage, team collaboration, data tracking using lists, Power Platform integrations, and internal communication.


Types of SharePoint Sites

When creating a new site, you'll choose between two main types. Each serves a different purpose, so picking the right one from the start saves you time later.

👥

Team Site

Built for collaboration. Teams use it to share files, track tasks, and work together on projects day-to-day.

  • Project documents
  • Team data tracking
  • CRM document integration
  • Internal collaboration
📢

Communication Site

Built for broadcasting. Use it to share information with a large group — announcements, news, or company updates.

  • Company announcements
  • Internal portals
  • News updates
  • Department information

SharePoint vs Other Databases

Not every database is the right tool for every job. Here's how SharePoint compares to the other common choices in the Microsoft ecosystem.

Feature SharePoint Dataverse SQL Database
Document Storage Very Good Limited Not Recommended
Structured Data Good Excellent Excellent
Power Platform Integration Easy Native Needs Setup
Best Use Documents & Simple Data Business Applications Complex Data Systems

SharePoint Lists

A SharePoint List is like a table where you can store structured data. It works similarly to Excel but with more control, sharing options, and automation support. Lists are often used as a data source in Power Apps and Power Automate.

// SharePoint list — supported column types
const columnTypes = [
  'Single line text',  'Multiple line text',
  'Number',  'Date & Time',  'Yes/No',
  'Person or Group',  'Attachment',
  'Choice (Dropdown)',  'Hyperlink'
];
📝 Text (single line)
📄 Text (multi-line)
🔢 Number
📅 Date & Time
✔ Yes / No
👤 Person or Group
📎 Attachment
📊 Choice (Dropdown)
🔗 Hyperlink
SharePoint List Example

↑ SharePoint List — structured data, similar to Excel but with automation support


Document Library

A Document Library is where files live in SharePoint. You can upload documents, organize them into folders, control who can access them, and track every version change automatically. It is the backbone of document management in the Microsoft ecosystem.

Common uses include document storage, version tracking, permission control, and Dynamics 365 document integration.

SharePoint Document Library

↑ Document Library — file storage with version history and permission controls


How to Create a SharePoint Site

Follow these five steps to get your first SharePoint site up and running.

01

Open SharePoint

Go to office.com, sign in with your Microsoft 365 account, and open SharePoint from the app launcher in the top-left corner.

Open SharePoint from office.com

↑ Open SharePoint from the app launcher at office.com

02

Click "Create Site"

From the SharePoint home page, click + Create site. You will be presented with two options — choose the one that fits your needs.

  • Team Site — For collaboration and project work
  • Communication Site — For announcements and company updates
Create Site options

↑ Choose between Team Site and Communication Site

03

Choose a Template

Select a modern template from Microsoft's template gallery, or go with the default Standard Team template. Templates give you a pre-built structure you can customize later.

Template selection

↑ Pick a template or use the default Standard Team layout

04

Enter Site Details

Fill in the details for your new site. Every field here matters, so take a moment to get them right.

  • Site Name — The display name of your SharePoint site
  • Description — A short summary of the site's purpose (optional but helpful)
  • Privacy — Private: Only selected members can access · Public: Anyone in your org can view
  • Language — Choose carefully — this cannot be changed easily later
Site details form — part 1

↑ Enter your site name, description, and privacy setting

Site details form — part 2

↑ Set the preferred site language before proceeding

05

Add Members & Finish

Add owners and members who need access to the site. Click Finish — your SharePoint site is ready. You can now create lists, upload documents, customize pages, and connect to Power Platform or Dynamics 365.

Add members screen

↑ Add owners and members, then click Finish to create the site

✨ Remember: No need to make everything perfect from day one. Just start using SharePoint, try things out, and slowly you'll get comfortable with it. The best time to learn is while building something real.

Microsoft 365 · Power Platform · Dynamics 365 · SharePoint Guide

🌐 Understanding Dynamics 365 CE & Dataverse

 Whether you're just starting your journey as a Dynamics 365 Developer or preparing for that big interview, everything begins with a clear understanding of what you're actually building on. That means understanding what Dynamics 365 CE is, and more importantly, how Dataverse holds it all together.

Let’s break it down.

💡 What is Dynamics 365 CE?

When we say Dynamics 365 Customer Engagement (CE), we’re talking about a collection of Microsoft business applications focused on managing customer-facing processes. Think about:

  • 💼 Sales – for tracking leads, opportunities, and closing deals

  • 🎧 Customer Service – for handling cases, SLAs, and knowledge management

  • 📣 Marketing – for managing campaigns, segments, customer journeys

  • 🧰 Field Service – for dispatching technicians and managing assets

  • 📊 Project Operations – for managing resource utilization and project billing

All of these apps don’t live in isolation. They run on a shared platform called Dataverse.


🧠 So, What Exactly Is Dataverse?

You can think of Dataverse as the "database with superpowers."

It's not just where data is stored — it's the backbone of all Power Platform applications and Dynamics 365 CE modules. It handles things like:

  • Tables (Entities) – like Contact, Account, or Case

  • Relationships – one-to-many, many-to-many

  • Security roles & access control

  • Business logic – workflows, business rules, calculated fields

  • APIs – for developers to read/write/update data

🔍 Fun Fact: Dataverse was formerly known as Common Data Service (CDS). Microsoft rebranded it, but many principles are the same.


🏗️ Dataverse = A Developer’s Playground

If you're a D365 developer, here’s what makes Dataverse special for you:

  • You can customize tables, fields, and relationships without writing code.

  • You can write plugins to run server-side logic during operations like create/update/delete.

  • You can integrate external systems using the Web API or the SDK.

  • You can build rich Power Automate flows or Power Apps that talk directly to Dataverse.

In other words, it gives you the flexibility of a relational database with the power of a business platform.


🔐 Security Model in Dataverse

Security isn’t an afterthought — it’s baked in.

Dataverse provides a layered security model:

  • Business Units – Logical segregation of users (e.g., by department or geography)

  • Security Roles – Define what actions a user can perform (Read, Write, Delete, etc.)

  • Teams – Users can belong to multiple teams and inherit access

  • Hierarchy Security – Managers can access records of their reports

🛡️ This model ensures that data access is well-governed — a crucial need for enterprise-grade apps.


💬 Real-World Analogy

Imagine you're building an app to manage real estate assets. Dataverse lets you:

  • Create a A Property table with custom columns like Area, Price, Location

  • Link each property to an Owner (Account)

  • Restrict certain users to only see properties in their city (via business units)

  • Run a plugin to auto-calculate stamp duty based on the price

All of this happens inside Dataverse, without needing to build your own backend from scratch.


🎯 Interview Questions

1. What are the core components of the Power Platform?
Ans. Power Apps, Power Automate, Power BI, Power Pages, and Dataverse.

2. What is Dataverse?
Ans. Cloud-based data platform for storing and managing business data.

3. Difference between Dataverse and traditional SQL?
Ans. Dataverse offers metadata-driven logic, relationships, security, and integration support.

4. How is metadata stored and managed in Dataverse?
Ans. Metadata (like table schema, relationships) is stored in system tables and drives the platform's dynamic behavior.

5. What’s the difference between model-driven and canvas apps?
Ans. Model-driven apps are data-first (based on Dataverse), canvas apps are design-first (pixel control).

6. What’s the role of business units?
Ans. They define the data access boundary for users.

7. What is a business unit in D365 CE and how does it impact data access?
Ans. It creates a hierarchy that controls the visibility of records to users based on their assigned unit.

8. Can we control field-level security in Dataverse?
Ans. Yes, via Field Security Profiles

9. What is the difference between record ownership and access?
Ans. Ownership gives control over a record; access (via sharing, role, or team) allows interaction without owning.

10. What are Access Teams vs Owner Teams?
Ans. Owner Teams own records; Access Teams are temporary and used for granting record-level access dynamically.

11. What is the role of a solution in D365 CE?
Ans. A container to group and transport customizations like tables, fields, views, and flows.

12. Managed vs Unmanaged solutions?
Ans. Managed = for deployment, Unmanaged = for development.

13. Can we export a solution with data? If yes, how?
Ans. No, solutions don’t carry data. Use Data Export Service, Azure Data Factory, or dataflows.

14. What is patching in managed solutions?
Ans. Patches allow delivering small updates over a base managed solution, useful for hotfixes.

15. What is the difference between a patch and a clone of a solution?
Ans. A patch makes a small update to an existing solution; a clone creates a new major version that includes all prior patches.

16. Can you export a managed solution from a production environment?
Ans. No, only unmanaged solutions can be exported. Managed solutions are meant for deployment, not modification.

17. What happens if two managed solutions customize the same component?
Ans. The solution installed last wins (layering). Managed conflicts are resolved via solution layering.

18. What happens when you delete a managed solution from an environment?
Ans. All components included in that solution (that weren’t used elsewhere) are removed, making it risky in production.

18. Can you explain the solution layering model in D365 CE?
Ans. D365 uses a layered solution model:
        System Layer → Managed → Unmanaged.
        The top-most layer takes precedence.

19. What are polymorphic lookups in Dataverse (also called Customer or Regarding)?
Ans. These allow referencing more than one type of table (e.g., Customer can link to either Account or Contact).

20. Which APIs can developers use to access Dataverse?
Ans. Web API (REST), SDK via IOrganizationService (SOAP), and Data Export (for external sync).

21. What are some limitations of Dataverse developers should be aware of?
Ans. Some key limitations:
  • API limits (service protection throttling)
  • Complex joins are harder than in SQL
  • Plugin execution timeout (~2 minutes)
  • Storage can become expensive at scale



How to Get and Set Field Values in Dynamics 365 CRM using JavaScript

Get & Set Field Values in Dynamics 365 | JavaScript Guide
Dynamics 365 · JavaScript

Get & Set Field Values
in Dynamics 365

A complete JavaScript reference for all CRM field types

JavaScript formContext Power Platform CRM Automation
Customizing Dynamics 365 CRM using JavaScript allows you to dynamically retrieve and update field values, improving user experience and automation. This guide covers getValue() and setValue() patterns for every field type you'll encounter in a CRM form.

Getting Started

Every JavaScript customization in Dynamics 365 starts with getting the form context from the execution context. All field operations flow through this object.

Entry Point
JavaScript
function GetSet(executionContext) {
    var formContext = executionContext.getFormContext();
}

01Single Line & Multiple Lines of Text

📝 Used for textual data entry. Both single-line and multi-line text fields share the same getValue() and setValue() API.
Get Value
JavaScript
var name = formContext.getAttribute("xyz_name").getValue();
Set Value
JavaScript
formContext.getAttribute("xyz_name").setValue("John Doe");

02Two Options (Boolean) Fields

✅ Stores Yes/No or True/False values. getValue() returns a boolean; setValue() accepts true or false.
Get Value
JavaScript
var interested = formContext.getAttribute("xyz_interested").getValue();
Set Value
JavaScript
formContext.getAttribute("xyz_interested").setValue(true);

03Option Set (Dropdown) Fields

📊 Used for predefined selections. You can get/set by numeric ID or by text label. Setting by text requires looping through the available options.
Get Selected Value (Numeric ID)
JavaScript
var topic = formContext.getAttribute("xyz_topic").getValue();
Get Selected Text
JavaScript
var topicText = formContext.getAttribute("xyz_topic").getText();
Set Value Using ID
JavaScript
formContext.getAttribute("xyz_topic").setValue(772500003);
Set Value Using Text
JavaScript
var text = "Power Automate";
var optionSetValues = formContext.getAttribute("xyz_topic").getOptions();

for (var i = 0; i < optionSetValues.length; i++) {
    if (optionSetValues[i].text == text) {
        formContext.getAttribute("xyz_topic").setValue(optionSetValues[i].value);
    }
}

04Whole Number Fields

🔢 Used for storing integer values. getValue() returns a number; setValue() accepts a whole number.
Get Value
JavaScript
var age = formContext.getAttribute("xyz_age").getValue();
Set Value
JavaScript
formContext.getAttribute("xyz_age").setValue(30);

05Decimal & Floating Point Numbers

🔣 Used for precise numeric values. Decimal fields store fixed-precision numbers; floating point fields store approximate values with higher range.
Get Decimal Value
JavaScript
var dn = formContext.getAttribute("xyz_dn").getValue();
Set Decimal Value
JavaScript
formContext.getAttribute("xyz_dn").setValue(45.6);
Get Floating Point Value
JavaScript
var fpn = formContext.getAttribute("xyz_fpn").getValue();
Set Floating Point Value
JavaScript
formContext.getAttribute("xyz_fpn").setValue(0.00008);

06Date Fields

📅 Used to store date and date-time values. getValue() returns a JavaScript Date object; pass a Date object to setValue().
Get Value
JavaScript
var dateField = formContext.getAttribute("xyz_date").getValue();
Set Value (Current Date)
JavaScript
formContext.getAttribute("xyz_date").setValue(new Date());

07Currency Fields

💰 Stores financial values. Works identically to decimal fields — returns a number and accepts a number. The currency symbol is controlled by the record's currency setting.
Get Value
JavaScript
var amount = formContext.getAttribute("xyz_amount").getValue();
Set Value
JavaScript
formContext.getAttribute("xyz_amount").setValue(876.78);

08Multi-Select Option Set Fields

☑️ Allows selecting multiple predefined values. getValue() returns an array of numeric IDs; setValue() takes an array. Setting by text requires matching each label against getOptions().
Get Selected Values (Array of IDs)
JavaScript
var selectedValues = formContext.getAttribute("xyz_country").getValue();
Get Selected Texts
JavaScript
var selectedTexts = formContext.getAttribute("xyz_country").getText();
Set Values Using IDs
JavaScript
formContext.getAttribute("xyz_country").setValue([772500000, 772500002, 772500005]);
Set Values Using Texts
JavaScript
var selectedOptions = [];
var optionText = ["India", "Brazil", "Canada"];
var optionSetValues = formContext.getAttribute("xyz_country").getOptions();

for (var i = 0; i < optionText.length; i++) {
    for (var j = 0; j < optionSetValues.length; j++) {
        if (optionText[i] === optionSetValues[j].text) {
            selectedOptions.push(optionSetValues[j].value);
        }
    }
}
formContext.getAttribute("xyz_country").setValue(selectedOptions);

09Lookup & Customer Fields

🔗 Used to reference records like Contacts and Accounts. getValue() returns an array with one object containing id, entityType, and name. setValue() takes the same structure.
Get Lookup Record Details
JavaScript
var lookupValue = formContext.getAttribute("xyz_author").getValue();

var authorGuid       = lookupValue ? lookupValue[0].id         : null;
var authorEntityType = lookupValue ? lookupValue[0].entityType : null;
var authorName       = lookupValue ? lookupValue[0].name       : null;
Set Lookup Value
JavaScript
var lookupRecord = [{
    id:         "0d849e72-362b-eb11-a813-000d3af010d0",
    entityType: "contact",
    name:       "John Doe"
}];

formContext.getAttribute("xyz_author").setValue(lookupRecord);

Conclusion

Understanding how to get and set field values in Dynamics 365 using JavaScript helps improve form automation and user experience. By leveraging these scripting techniques, you can customize CRM behavior efficiently — from simple text fields to complex lookups and multi-select options.


FAQs

Q1 Can I update fields dynamically based on other field values?
Yes. Use the onChange event to trigger scripts when a field's value changes. Register your function on the field's OnChange event in the form editor, and it will fire every time the user modifies that field.
Q2 How do I reset a field to blank?
Pass null to setValue(). This works for all field types.
JavaScript
formContext.getAttribute("xyz_fieldname").setValue(null);
Q3 Where do I place this JavaScript code in Dynamics 365?
Create a Web Resource (type: JavaScript) in your solution, paste your function there, and then link it to the form's events — such as OnLoad or OnChange — through the form editor's event handler settings.

✨ Tip: Always check that getValue() doesn't return null before reading properties from the result — especially for Lookup fields. A quick null check prevents the most common runtime errors in CRM scripts.

Dynamics 365 · JavaScript · Power Platform · CRM Customization Guide