locked
Running scripts on global search page RRS feed

  • Question

  • Hi Everyone,

    I am interested if it is possible to run a custom script on the page which lists the global search results.

    Do you think it is possible in a preferably supported way?

    Regards,

    Adam

    Monday, September 14, 2015 11:30 AM

All replies

  • For this you need to create a html web resource and add this in your form.

    In your html web resource add javascript to retrieve data based to search.

    create a html table  and add your script result to your html table.

    Sample:=

    /// <reference path="jquery-1.7.1.min.js.js" />


    var

    context = Xrm.Page.context;


    //var context = GetGlobalContext();


    var

    serverUrl = context.getServerUrl();


    var

    ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

    functionGetData(contactID) {

    retrieveMultiple(

    "ContactSet", "(guid'"+ contactID + "')?$expand=listcontact_association", GetContactMarketingListCompleted, ErrorMessage, null);

    }

    function

    retrieveMultiple(odataSetName, filter, successCallback, errorCallback, returnData) {

       

    if(!odataSetName) {

            alert(

    "odataSetName is required.");

           

    return;

        }

       

    varodataUri = serverUrl + ODATA_ENDPOINT + "/"+ odataSetName;

       

    if(filter) {

            odataUri += filter;

        }

        $.ajax({

            type:

    "GET",

            contentType:

    "application/json; charset=utf-8",

            datatype:

    "json",

            url: odataUri,

            async:

    false,

            beforeSend:

    function(XMLHttpRequest) {

                XMLHttpRequest.setRequestHeader(

    "Accept", "application/json");

            },

            success:

    function(data, textStatus, XmlHttpRequest) {

               

    if(successCallback) {

                   

    if(data && data.d && data.d.results) {

                       

    varnext;

                       

    if(data.d.__next) {

                            next = data.d.__next;

                        }

                        successCallback(data.d.results, textStatus, XmlHttpRequest, returnData,next);

                    }

                   

    elseif(data && data.d) {

                        successCallback(data.d, textStatus, XmlHttpRequest, returnData);

                    }

                   

    else{

                        successCallback(data, textStatus, XmlHttpRequest, returnData);

                    }

                }

            },

            error:

    function(XmlHttpRequest, textStatus, errorThrown) {

               

    if(errorCallback)

                    errorCallback(XmlHttpRequest, textStatus, errorThrown);

               

    else


                    errorHandler(XmlHttpRequest, textStatus, errorThrown);

            }

        });

    }


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Tuesday, September 15, 2015 9:54 AM
  • Hi Santosh,

    My problem is that as far as I know the global search result page is not considered a form in the Dynamics CRM terminology, so I cannot add an html page to it with the standard approach.

    Regards,

    Adam

    Thursday, September 17, 2015 11:41 AM
  • Hi,

    One trick I have used in the past is to add the web resource to one of the buttons on none form pages. However I have just tried this on the global search page and can't find which buttons to customise for it. I thought it would be the application ribbon but it isn't.

    Anyway if you can find which ribbon buttons theyare you can add a resource to the enable rules but call the Nan function this will load you scripts, however you may need to go unsupported to detemine if it is actually the global search page.

    Chris

    Monday, September 21, 2015 3:42 PM