I have a created a custom ribbon button that opens an HTML dialog, I need to pass the the selected rows into the dialog and when click submit I want to create/add a record to the selected rows. Thanks!
*This post is locked for comments
I have a created a custom ribbon button that opens an HTML dialog, I need to pass the the selected rows into the dialog and when click submit I want to create/add a record to the selected rows. Thanks!
*This post is locked for comments
[quote user="Rookie-CRMing"]This solution does not work for me. It tells me 'Xrm.Page.getControl(...) is null'.[/quote]
Your control name cannot have spaces. Check it in the Form Designer and use the control's name.
I think you may need to be careful if this is an Editable Grid rather than the standard Read-only grid as it has different mechanisms for interacting with the related data.
Hope that helps.
This solution does not work for me. It tells me 'Xrm.Page.getControl(...) is null'.
Rather than use the getGrid.getSelectedRows - the best option for ribbon buttons is to use the selectedItems passed to the function as I describe at ribbonworkbench.uservoice.com/.../129783-pass-the-currently-selected-grid-row-s-to-a-custo
It is an array that will give you the Id of the items which you can then use in your query.
Thank you Scott and Ramanathan.
Here is my code that I will be using to select rows from a view and add/create a record to the selected rows. I will call this code from the ribbon workbench. I know the code isn't quite right, I would appreciate if you guys can point me on what I need to do. Thanks!
// JavaScript source code var selectedEntityReferences = []; var selectedRows = Xrm.Page.getControl("Active Contacts>").getGrid().getSelectedRows(); selectedRows.forEach(function (selectedRow, i) { selectedEntityReferences.push(selectedRow.getData().getEntity().getEntityReference()); }); function createOperationUsingWebAPI() { var clientUrl = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest() req.open("POST", encodeURI(clientUrl + "/api/data/v8.0/accounts"), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { var accountUri = this.getResponseHeader("OData-EntityId"); }; var body = JSON.stringify({ "name": "Sample Account", "creditonhold": false, "address1_latitude": 47.639583, "description": "This is the description of the sample account", "revenue": 5000000, "accountcategorycode": 1 }); req.send(body); }
Do you mean on a standard ribbon button associated to a sub-grid.
If so you can use my how-to article here - ribbonworkbench.uservoice.com/.../129783-pass-the-currently-selected-grid-row-s-to-a-custo
Hope this helps
we can create records using webapi and relate records by populating lookup fields, below is the reference for all CRUD operations
scaleablesolutions.com/crud-operations-using-microsoft-dynamic-crm-web-api
Reference for webapi lookup
exptechsolutions.blogspot.com/.../know-how-set-lookup-value-on.html
Got it thanks, Ramanathan. How do I create a corresponding record for the selected rows upon submission?
To get the selected row from a grid below are the code and reference. I am not clear with the dialog part, If its a webresouce you can pass selected id's as URL or directly access the grid to get selected records and perform the create operation as needed on submit click.
var selectedEntityReferences = [];
var selectedRows = Xrm.Page.getControl("<grid name goes here>").getGrid().getSelectedRows();
selectedRows.forEach(function (selectedRow, i) {
selectedEntityReferences.push(selectedRow.getData().getEntity().getEntityReference());
});
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156