locked
Form Selector on Bulk Edit RRS feed

  • Question

  • For bulk edit, I want the user to be redirected to a different form other than the one pulled from UserEntityUISettings. I am using

    Xrm.Page.ui.formSelector.items.get(itemId).navigate();

    However items collection is empty when Form Type is 6 (bulk edit). I don't want to use direct navigation, because of other complexities involved with it in editing and saving bulk records. Is there any alternative?

    Monday, February 11, 2013 1:58 PM

Answers

  • So here is how I solved the problem.

    1. Using the Ribbon Workbench tool override the default bulkEdit function call with your own custom function that take three parameters as specified in the bulkEdit function signature.

    2. In your custom function retrieve the UserEntityUISettings based on the owner and objecttypecode, save the LastViewedFormXML value in a variable.

    3. Override the UserEntityUISettings LastViewedFormXML attribute to the form id that you want the user to be redirected to for Bulk Edit.

    4. Reset back the UserEntityUISettings LastViewedFormXML back to the one originially set by CRM default behavior.

     Here is the fetch code:

    var request = "<fetch mapping='logical' count='10'>" +
                        "<entity name='userentityuisettings'>" +
                        "<attribute name='userentityuisettingsid' />" +
                        "<attribute name='lastviewedformxml' />" +
                        "<filter type='and'>" +
                        "<condition attribute = 'ownerid' operator='eq' value='" + Xrm.Page.context.getUserId() + "'/>" +
                        "<condition attribute='objecttypecode' operator='eq' value='" + selectedEntityTypeCode + "' />" +
                        "</filter>" +
                        "</entity>" +
                        "</fetch>";
            var serverUrl = Xrm.Page.context.getServerUrl();
            var orgName = Xrm.Page.context.getOrgUniqueName();
            var orgService = new FetchUtil(orgName, serverUrl);
            var retrievedRecords = orgService.Fetch(request);
            var lastviewed = retrievedRecords[0].attributes["lastviewedformxml"].value;
            var result = retrievedRecords[0].attributes["userentityuisettingsid"].value;

    Set the lastviewed xml to your bulk edit form

    var entitySettings = new Object();
                            entitySettings.LastViewedFormXml = "<MRUForm><Form Type=\"Main\" Id=\"" + bulkEditFormID + "\" /></MRUForm>";
                            updateRecordSync(result, entitySettings, "UserEntityUISettingsSet");

    Launch the Bulk Edit form and reset the last viewed attribute back to its orginal:

    Mscrm.GridRibbonActions.bulkEdit(selectedControl, selectedItemReferences, selectedEntityTypeCode);

            var entitySettingsReset = new Object();
            entitySettingsReset.LastViewedFormXml = lastviewed;
            updateRecordSync(result, entitySettingsReset, "UserEntityUISettingsSet");

    You may want to put this inside a check that more than one records have been indeed selected to launch the bulk edit form:

    if (selectedItemReferences.length > 1)

    • Marked as answer by SandeepCh Saturday, February 16, 2013 5:41 AM
    Saturday, February 16, 2013 5:40 AM

All replies

  • Hi,

    Are you doing this:

    SDK.FormItemSamples.getFormItems();

    I see this in this article: http://msdn.microsoft.com/en-us/library/gg309560.aspx

    Hope this helps.
    If i answered your question, please mark the response as an answer and also vote as helpful.


    Pedro Azevedo Crm Specialist 4.0\2011

    • Proposed as answer by Azevedo PedroMVP Monday, February 11, 2013 4:15 PM
    • Unproposed as answer by SandeepCh Monday, February 11, 2013 7:47 PM
    Monday, February 11, 2013 4:15 PM
  • Yes, I tried doing that. But Xrm.Page.ui.formSelector.items collection returns an empty array in the bulk edit form.
    • Edited by SandeepCh Monday, February 11, 2013 7:48 PM
    Monday, February 11, 2013 7:46 PM
  • I believe this is a limitation of the product at this stage.  The "Bulk Edit" form is always the "default" form for the entity.  As stated in the SDK:

    When there is only one form available the Xrm.Page.ui.formSelector.items Collection is empty and the getCurrentItem method will return null.

    There are no published work-arounds that I'm familiar with.  You can up-vote this item on Microsoft Connect to bring some popularity to this issue.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.



    Tuesday, February 12, 2013 12:41 AM
    Moderator
  • Hi Zouma,

    I did see that post, but it is applicable if I am trying to perform some action on the fields based on the records. But requirement is different than that. I need to be able to show a different form just for bulk edit, based on the security roles of the user.

    Tuesday, February 12, 2013 9:12 AM
  • Thanks Dave.

    What alternative do I have to show a different form for bulk edit other than the one that CRM picks from UserEntityUISettings?

    Regards,

    Sandeep

    Tuesday, February 12, 2013 9:14 AM
  • The best thing you can do, is train your people:

    http://crmmongrel.blogspot.com/2012/04/bulk-edit-with-role-based-forms.html


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.

    Tuesday, February 12, 2013 7:17 PM
    Moderator
  • Lol, thanks Dave. My users are customers of CRM since a while and they understand the product in and out. This is a requirement that suits a business proposition.
    Saturday, February 16, 2013 5:24 AM
  • So here is how I solved the problem.

    1. Using the Ribbon Workbench tool override the default bulkEdit function call with your own custom function that take three parameters as specified in the bulkEdit function signature.

    2. In your custom function retrieve the UserEntityUISettings based on the owner and objecttypecode, save the LastViewedFormXML value in a variable.

    3. Override the UserEntityUISettings LastViewedFormXML attribute to the form id that you want the user to be redirected to for Bulk Edit.

    4. Reset back the UserEntityUISettings LastViewedFormXML back to the one originially set by CRM default behavior.

     Here is the fetch code:

    var request = "<fetch mapping='logical' count='10'>" +
                        "<entity name='userentityuisettings'>" +
                        "<attribute name='userentityuisettingsid' />" +
                        "<attribute name='lastviewedformxml' />" +
                        "<filter type='and'>" +
                        "<condition attribute = 'ownerid' operator='eq' value='" + Xrm.Page.context.getUserId() + "'/>" +
                        "<condition attribute='objecttypecode' operator='eq' value='" + selectedEntityTypeCode + "' />" +
                        "</filter>" +
                        "</entity>" +
                        "</fetch>";
            var serverUrl = Xrm.Page.context.getServerUrl();
            var orgName = Xrm.Page.context.getOrgUniqueName();
            var orgService = new FetchUtil(orgName, serverUrl);
            var retrievedRecords = orgService.Fetch(request);
            var lastviewed = retrievedRecords[0].attributes["lastviewedformxml"].value;
            var result = retrievedRecords[0].attributes["userentityuisettingsid"].value;

    Set the lastviewed xml to your bulk edit form

    var entitySettings = new Object();
                            entitySettings.LastViewedFormXml = "<MRUForm><Form Type=\"Main\" Id=\"" + bulkEditFormID + "\" /></MRUForm>";
                            updateRecordSync(result, entitySettings, "UserEntityUISettingsSet");

    Launch the Bulk Edit form and reset the last viewed attribute back to its orginal:

    Mscrm.GridRibbonActions.bulkEdit(selectedControl, selectedItemReferences, selectedEntityTypeCode);

            var entitySettingsReset = new Object();
            entitySettingsReset.LastViewedFormXml = lastviewed;
            updateRecordSync(result, entitySettingsReset, "UserEntityUISettingsSet");

    You may want to put this inside a check that more than one records have been indeed selected to launch the bulk edit form:

    if (selectedItemReferences.length > 1)

    • Marked as answer by SandeepCh Saturday, February 16, 2013 5:41 AM
    Saturday, February 16, 2013 5:40 AM
  • Nicely done.

    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.

    Saturday, February 16, 2013 3:34 PM
    Moderator