web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Bulk Queue Assignment Not Working Using JavaScript in Dynamics 365

(1) ShareShare
ReportReport
Posted on by
Hi all,
We’ve implemented a custom “Move to Queue” button in Dynamics 365 CRM using JavaScript and `Xrm.WebApi`. The goal is to reassign selected case records from one queue to another by:
- Creating a new `queueitem`
- Removing the old one (from the previous queue)
The JavaScript function is registered on a **Command Bar button** at the **table (main grid) level**, and is triggered using:
```javascript
primaryControl.getGrid().getSelectedRows().forEach(row => {
  // logic to assign queueitem
});



❗However, the issue is:
No cases (even a single record) get reassigned
No error is shown
We suspect either the queueitem creation or loop logic is not functioning as expected from the main grid context
We are not using Power Automate. This is a pure JavaScript solution, and we'd like to know:
Is getSelectedRows() supported for this use case?
Is there a working example for assigning cases to a queue using JavaScript in bulk?
Any help or reference would be appreciated.
Thanks!
I have the same question (0)
  • surya narayanan Profile Picture
    92 on at
    Bulk Queue Assignment Not Working Using JavaScript in Dynamics 365
    Hi,
     
    1. Confirming: primaryControl.getGrid().getSelectedRows() Yes, this is supported and correct when you're on a main grid Command Bar button.
     
    primaryControl.getGrid().getSelectedRows().forEach(row => {
      const entityReference = row.getData().getEntity();
      const id = entityReference.getId(); // This is the GUID
      const entityType = entityReference.getEntityName(); // e.g., "incident"
    });
     
    So this part is fine, but be sure you're correctly extracting the ID and entity name.
     
    2. Assigning Cases to a Queue — Required Steps
    To move a Case to a different Queue, you don’t “reassign” the Case itself — you manipulate queueitem records:
     
    Find the existing queueitem for the case (if it exists)
    Delete the existing queueitem
    Create a new queueitem in the target queue
     
    3. Working JavaScript Sample — Bulk Move Cases to Another Queue
    Here's a complete working example, assuming you're using the Command Bar on the Case main grid:
     
    function moveCasesToQueue(primaryControl) {
      const targetQueueId = "00000000-0000-0000-0000-000000000000"; // ← replace with your queue GUID
      primaryControl.getGrid().getSelectedRows().forEach(async (row) => {
        const entity = row.getData().getEntity();
        const caseId = entity.getId().replace("{", "").replace("}", "");
        try {
          // Step 1: Get existing queueitem for the case (if any)
          const existingQueueItems = await Xrm.WebApi.retrieveMultipleRecords("queueitem", `?$filter=_objectid_value eq ${caseId} and objecttypecode eq 'incident'`);
          // Step 2: Delete existing queueitems
          for (let item of existingQueueItems.value) {
            await Xrm.WebApi.deleteRecord("queueitem", item.queueitemid);
          }
          // Step 3: Create new queueitem in the target queue
          const newQueueItem = {
            "objectid_incident@odata.bind": `/incidents(${caseId})`,
            "queueid@odata.bind": `/queues(${targetQueueId})`
          };
          await Xrm.WebApi.createRecord("queueitem", newQueueItem);
          console.log(`Moved case ${caseId} to queue successfully.`);
        } catch (err) {
          console.error(`Failed to move case ${caseId}`, err);
          Xrm.Navigation.openAlertDialog({ text: `Error moving case: ${err.message}` });
        }
      });
    }

    Optional Enhancements:
    Add a confirmation dialog before executing
    Show a success/failure dialog with a summary
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 149

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 132

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 123 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans