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