3, 2, 1, Action! All records on all the pages in CRM grids

You have a workflow, you have 5000+ records, and you do an advanced find, it brings back the records only to find that you can run the workflow on a maximum on 250! (With unsupported customizations you can increase this limit but let’s stay out of that space for now)

If it’s a one off you can manually go through each page, run the workflow and move onto the next page, but if you have to perform this task everyday it becomes a nightmare. The good news is with a small ISV extension and a click of a button it’s done, magic!

To do this, we’ll be using the FetchXml form input that’s exposed when an advanced find query is run, once we have the FetchXml we simply create an instance of CrmService, execute the query and perform whatever action we like on the result set.

 How to find the FetchXml form input

  1. Do an advanced find query on anything
  2. Open IE Developer Toolbar by pressing F12
  3. Use the Select Element By Click option highlight the advanced find result section
  4. Expand the form node and you’ll see the FetchXml

That’s great, how do we get access to this programmatically?

  1. Export the isv.config file
  2. Open it up and add the following xml
    <Entities>
        <Entity name=”account”>
            <Grid>
                <MenuBar>
                    <Buttons>
                        <Button JavaScript="window.showModalDialog('/isv/magnetism/action.aspx', this, 'dialogHeight: 300px; dialogWidth: 300px;');”>
  3. Import and publish customizations

The reason we’re not using the out of the box Url attribute is because we want to reference the parent window from the child window (/isv/magnetism/action.aspx) so that we can access any element from our custom aspx page. To do that we pass ‘this’ as a parameter to the showMoalDialog methods’ dialogArguments input parameter.

Are we there yet?

The final step is to create the aspx page, grab the FetchXml then execute. The example below grabs the query (FetchXml) from the advanced find page and puts it into a textbox that you have full control over, therefor it can be accessed with server side code enabling you to do whatever you wish…

<%@ Page Language="cs" %> 
<html>
<head runat="server">
    <base target="_self" />
    <meta http-equiv="Expires" content="-1">
    <meta http-equiv="Pragma" content="no-cache">
</head>
<body>
    <asp:TextBox ID="fetchxml" runat="server" />
    <script type="text/javascript">
        var o = window.dialogArguments;
        document.getElementById("fetchxml").value =
            o.parent.document.getElementById("FetchXml").value);
     </script>
</body>
</html>

Since this is a modal dialog, couple of tips

  • Use base target=”_self”, otherwise when you post back it’ll pop another window
  • Force the browser not to cache the page

Enjoy!

No Comments