Creating\updating system view (SavedQuery) via javaScript RRS feed

  • Question

  • Hi, i want to create view and that update it with dynamic parameter (i can to create one and update it all time parameter). For example i have view "Dynamic contacts  view" i get "name"  parameter so i want to open the view all the contacts with this name. I saw how to do that with c# but i need to use JS,

    thanks in advance.

    Monday, June 1, 2015 1:10 PM

All replies

  • Do you want to prompt the user for the 'name' and then build the query/view?  

    In either case you could probably do this with a WebResource, but it will take some work.

    Will the Quick find feature on Contact not work for what you are attempting to do?

    Monday, June 1, 2015 1:39 PM
  • Hi thank you,

    I can get one of two parameter in some form (telephone or name) and want to build the view and popup it automatically,

    because that it should be done in code.

    if you know another way please tell me, or if you can to direct me how do this via js. 

    Something like this  (https://msdn.microsoft.com/en-us/library/gg328457.aspx) just i want do this in js.

    • Edited by ran-j Tuesday, June 2, 2015 6:34 AM
    Tuesday, June 2, 2015 5:51 AM
  • You can't do this directly with a view, at least not that I am aware or have tried.  However, you can do this with some custom HTML and JS in web resources.

    You can use a tool called the CRM REST builder to help build the query.  https://crmrestbuilder.codeplex.com/

    The tool will help you to get the structure of the query you can load into some JS code.  Then you will need to combine this JS with an HTML webresource to prompt the user for the parameter, run the JS, then display the results in a table.  Not the same as a view, but it can be done.

    Tuesday, June 2, 2015 12:06 PM
  • Thank you,

    I solved it in this way :

    I created system view in crm, in JS file I created object (save query) with the property FetchXml (with the new fetch),

    at the end the call for the REST update function do the work

    SDK.REST.updateRecord(queryId, updateSavedQuery, "savedQuery", updateSuccessCallback, errorHandler);

    • Edited by ran-j Tuesday, June 9, 2015 11:39 AM
    Tuesday, June 9, 2015 10:34 AM
  • Hi,

    Refer bellow code it may be helpful for your requirement

    function setContactLookup(lookupFieldName, contactName) {
       // add the randomly generated GUID for the view id
       var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E3}";
       var entityName = "contact";
       // add the view display name
       var viewDisplayName = "Active Contacts";
       // fetch xml for filtered contact records
       var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" + 
                                   "<entity name='contact'>" + "<attribute name='fullname' />" + 
                                      "<attribute name='contactid' />" + 
                                      "<order attribute='fullname' descending='false' />" + 
                                      "<filter type='and'>" + 
                                          "<condition attribute='name' operator='eq' value='" + contactName + "' />" + 
                                      "</filter>" + 
                                   "</entity>" +
       // Grid Layout
       var layoutXml = "<grid name='resultset' " + 
       "object='1' " + 
       "jump='contactid' " + 
       "select='1' " + 
       "icon='1' " + 
       "preview='1'>" + 
       "<row name='result' " + 
       "id='contactid'>" + 
       "<cell name='fullname' " + 
       "width='200' />" + 
       "</row>" + 
       // add the custom view for the lookup field
       Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
    //The following line is the an unsupported way of disabling the View Picker, currently there is no supported way.
        document.getElementById(lookupFieldName + "_i").setAttribute("disableViewPicker", "1");
        //document.getElementById(lookupFieldName).setAttribute("disableViewPicker", "1");
       // disable the view picker and new button to restrict creating or adding non filtered contact records records
       //eval("crmForm.all." + lookupFieldName + ".AddParam('ShowNewButton', '0');");
       //eval("crmForm.all." + lookupFieldName + ".AddParam('DisableViewPicker', '1');");

    Wednesday, June 24, 2015 6:06 AM