Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Develop Custom Search in CRM

Posted on by 594

Hi CRM Folks,

I have a business requirement (probably redundant) but required for me.

I need to develop a HTML page (which will open on click of a button on contact entity) where it has following properties:

1. It should have a search bar where my business users can type any of the contacts name and it should pull up all the matching contacts name.

2. It should have a drop down from where my users can select these three options (All, active, inactive). If user select inactive, my search should only show inactive contacts. If he selects active, my search shows only active contacts. If he selects all, it should show both active & inactive contacts.

3. All the data extracted needs to be framed in JQgrid so that it has pagenation and some other fancy stuff.

Please help me out where to start. Also please support me with some useful documents/msdn articles/3rd party materials to start with.

*This post is locked for comments

  • Verified answer
    RE: Develop Custom Search in CRM

    You need to make a WebAPI call to execute your search request. there are 2 options to make search query one using REST call with OData format other is preparing fetchXml and wxecuting with WebAPI. I would suggest to do it with fetchXml because it will be more robust as you can verify it before executing and fetchXml has more readable format.

    See how to execute fetchXml with WebAPI www.ashishvishwakarma.com/test-fetchxml-with-webapi-dynamics-365-fetchxml-tester

    See how to validate fetchXml before executing https://www.ashishvishwakarma.com/validate-dynamically-generated-fetchxml-against-schema-before-executing/ this post is for C# you can achieve it in JS too. but it might be heavy to execute on client side so you can decide whether to validate or not. by the way instead of validate against schema you can quickly verify whether XML is valid or not.

    function parseXml(fetchXml) {
        debugger;
        try {
            var parser = new DOMParser();
            var parsedXml = parser.parseFromString(fetchXml, "text/xml");
            isValidXml = true;
            return parsedXml;
        } catch (err) {
            isValidXml = false
            alert("fetchXml entered in invalid : " + err.message);
        }
    }


  • Suggested answer
    Samit Paul Profile Picture
    Samit Paul 85 on at
    RE: Develop Custom Search in CRM

    Hi,

    You can use Lucene.NET Search Engine Framework to perform searching instead of writing the entire searching logic of your own.

    Thanks and Regards,

    Samit

  • Suggested answer
    keyur7379 Profile Picture
    keyur7379 900 on at
    RE: Develop Custom Search in CRM

    Hi chakkay,

    1.First you have to make HTML web resource. Use jquery data table because it is provides you default search button for all bind column.

    2.Use crm rest builder tool for getting data from crm.

    3. Bind this data in jquery data table.

    4. You have to put custom drop down for filter active or inactive and pass this filer in rest api filter.

    I am sure it is really work for you.

    Note : add jquery data table ref in your crm web resource and use in HTML web resource.

    Please use this code for your reference.

    <html><head>
        <link href="xxxxxxxxxx.crm8.dynamics.com/.../zep_bootstrap.min.css" rel="stylesheet">
        <link href="xxxxxxxxxx.crm8.dynamics.com/.../zep_jquery.dataTables.min.css" rel="stylesheet">
        <link href="maxcdn.bootstrapcdn.com/.../font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
        <style>
            .inputtext {
                height: 30px
            }

            .form-control {
                font-size: 0.9rem !important;
            }

            th {
                font-family: sans-serif,"Segoe\ UI\ Semibold",Tahoma;
                font-size: 11px;
                font-style: normal;
                font-variant: normal;
                font-weight: 700;
                line-height: 20px;
            }

            td {
                font-family: Arial,"Segoe\ UI",Tahoma;
                font-size: 13px;
                font-style: normal;
                font-variant: normal;
                font-weight: 400;
                line-height: 20px;
            }

            div {
                font-family: Arial,"Segoe\ UI",Tahoma;
                font-size: 13px;
                font-style: normal;
                font-variant: normal;
                font-weight: 400;
                line-height: 20px;
            }

            .ddlCurrency option {
                font-family: Arial,"Segoe\ UI",Tahoma !important;
                font-size: 13px !important;
                font-style: normal !important;
                font-variant: normal !important;
                font-weight: 400 !important;
                line-height: 20px !important;
            }

            select.form-control:not([size]):not([multiple]) {
                height: calc(1.90rem + 2px) !important;
            }

            #ddlCurrency select {
                background: transparent !important;
                width: 170px !important;
                color: grey !important;
                border: 0 !important;
                border-radius: 0 !important;
                height: 10px !important;
            }
        </style>
    <meta><meta></head>
    <body style="word-wrap: break-word;">
        &nbsp;&nbsp;&nbsp;<button id="btnShow" class="btn btn-default btn-sm float-right" onclick="ShowData();"> <i class="fa fa-refresh"></i></button>&nbsp;<img src="zep_loading_icon" id="img" style="display:none" width="100px">
        <table class="table table table-hover table-striped table-bordered compact">
            <thead>
                <tr>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                    <th>Column1</th>
                </tr>
            </thead>
            <tbody></tbody>
            <tfoot></tfoot>
        </table>
        <script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
        <script src="xxxxxxxxxx.crm8.dynamics.com/.../zep_jquery-3.2.1.min.js"></script>
        <script src="xxxxxxxxxx.crm8.dynamics.com/.../zep_jquery.dataTables.min.js"></script>
        <script src="xxxxxxxxxx.crm8.dynamics.com/.../zep_moment.min.js"></script>

        <script>
            $(document).ready(function () {
                $(".table").hide();
                GetData();
            });
            function ShowData() {
                GetData();
            }
        </script>
        <script>
            function GetData() {
                $('#img').show();
                //var ID = 897;
                var ID = window.parent.Xrm.Page.getAttribute('xxxxxxxxxx_navcustomercode').getValue();
                
                
                //Here you have to fetch data(Contact) from crm using rest api.
                //first install rest builder in online crm
                //fetch contact from crm
                
            }
            function bindData(data) {
                $(".table").dataTable().fnDestroy();
                var tbl = $('.table').DataTable(
                    {
                        "paging": true,
                        "autoWidth": false,
                        "searching": true,
                        "info": true,
                        "aaData": data,
                        "aoColumns": [
                            {
                                "sTitle": "Order Type", "mData": "OrderType", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Actual Rate", "mData": "ActualRate", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Execute Rate", "mData": "ExecutRate", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Virtual Currency", "mData": "VirtualCurrency", className: "dt-head-center dt-center"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Virtual Currency Amount", "mData": "VirtualCurrencyAmount", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Fiat Currency", "mData": "FiatCurrency", className: "dt-head-center dt-center"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Virtual Fees", "mData": "VirtualFees", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Fiat Fees", "mData": "FiatFees", className: "dt-head-center dt-right"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Invoice Number", "mData": "InvoiceNumber", className: "dt-head-center dt-left"
                                , "render": function (mData, type, full, meta) {
                                    return mData;
                                }
                            },
                            {
                                "sTitle": "Created Date", "mData": "CreateDate", className: "dt-head-center dt-center"
                                , "render": function (mData, type, full, meta) {
                                    return moment(mData).format('DD/MM/YYYY HH:mm:ss');
                                }
                            },
                            {
                                "sTitle": "Modified Date", "mData": "ModifyDate", className: "dt-head-center dt-center"
                                , "render": function (mData, type, full, meta) {
                                    return moment(mData).format('DD/MM/YYYY HH:mm:ss');
                                }
                            }
                        ]
                    });
            }
        </script>


    </body></html>

    Thanks,

    keyur shah

  • chakkay Profile Picture
    chakkay 594 on at
    RE: Develop Custom Search in CRM

    This looks like a good suggestion for me.

    But my business feels this as burdensome. They want something like a single button press and everything should happen. The custom search thing they proposed is the most comfortable option for them out of 5-6 different out of box search criteria provided natively by CRM.

    Anyways thats a good idea again! Please do provide me with some information if you know on how to develop that custom search.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Develop Custom Search in CRM

    That's right. What about just using the Filtering, and using Full Name or First and Last Names...

  • chakkay Profile Picture
    chakkay 594 on at
    RE: Develop Custom Search in CRM

    Hi Aric,

    Thanks for replying.

    You are perfectly correct this requirement is an overkill. I do support your option of using quick find. But the problem with quick find is we cannot apply a filter on that.

    Suppose assume i did customize the quick find view so that i will be displaying both active and inactive contacts. When i search a contact by name i do get both active & inactive contacts. But when i click the filter button, CRM pops up a message saying "This feature is disabled". There lies the bottleneck. That is the reason my business want to try a new method.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Develop Custom Search in CRM

    Hi Chakkay,

    It is a little of an overkill to develop something like this, when the system provides you with the same functionality, but in slightly a different way.

    The Quick Find on the Contacts Home Page view allows you to search for Contact by any of the fields that are select in the Quick Find View (Add Find Columns). This can be first name, last name, email address and other fields as well.

    Once you have searched by name, if you add the Status column to your view, you can use the Filter in your view results to filter by All, Active or Inactive (or you can have your custom views if you need).

    Pagination is out of the box feature, so you should not have any problem with that. The number of results per page is an individual setting that can be set using the Settings -> Options, and in the Records Per Page drop down select the number of records per page. The max selection there is 250.

    Quick Find Article:

    arunpotti.wordpress.com/.../how-to-configure-and-search-using-quick-find-view-in-ms-crm

    I hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans