Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

Dynamic Search

Posted on by Microsoft Employee

Is it possible to somehow create an advanced search function in NAV?

Etc. you are on customer list and you can search on Customer's Name, Adress and phone nr. in same search field without switching the filter.

So it would search in all of those fields just by typing search word in one place.

I have searched online if someone already did it but came up empty.

*This post is locked for comments

  • Verified answer
    p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    Try this object - it actually work for me

    OBJECT Page 50080 Search Customer
    {
    OBJECT-PROPERTIES
    {
    Date=14/04/16;
    Time=15:51:09;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    SourceTable=Table18;
    PageType=List;
    SourceTableTemporary=Yes;
    }
    CONTROLS
    {
    { 1000000000;0;Container;
    ContainerType=ContentArea }

    { 1000000011;1;Group ;
    GroupType=Group }

    { 1000000012;2;Field ;
    CaptionML=ENG=Type to search;
    SourceExpr=SearchString;
    OnValidate=BEGIN
    DoSearch;
    END;
    }

    { 1000000001;1;Group ;
    Name=Group;
    GroupType=Repeater }

    { 1000000002;2;Field ;
    SourceExpr="No." }

    { 1000000003;2;Field ;
    SourceExpr=Name }

    { 1000000004;2;Field ;
    SourceExpr="Search Name" }

    { 1000000005;2;Field ;
    SourceExpr="Name 2" }

    { 1000000006;2;Field ;
    SourceExpr=Address }

    { 1000000007;2;Field ;
    SourceExpr="Address 2" }

    { 1000000008;2;Field ;
    SourceExpr=City }

    { 1000000009;2;Field ;
    SourceExpr=Contact }

    { 1000000010;2;Field ;
    SourceExpr="Phone No." }

    }
    CODE
    {
    VAR
    SearchString@1000000000 : Text;

    LOCAL PROCEDURE DoSearch@1000000002();
    VAR
    Cust@1000000000 : Record 18;
    BEGIN
    Cust.RESET;
    Cust.SETFILTER(Name, '@*' + SearchString + '*');
    IF Cust.FINDSET THEN
    REPEAT
    INIT;
    Rec := Cust;
    IF INSERT THEN;
    UNTIL Cust.NEXT = 0;
    END;

    BEGIN
    END.
    }
    }

  • p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    You can read about query object on MSDN, they surely explain better than i can. But my ide was to use ADO automation and query sql server directly from nav code. I used this approach before, for nav2009 - can't see why it wouldn't work.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamic Search

    Ok thanks alot, I will try that.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamic Search

    I haven't used queries together with nav before. Can you give an example on how to set this up?

  • p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    Or, if there is not hundreds of thousands of customers - just use 4x filter& repeat loop to populate your table.

    say:

    cust.setfilter("Name",  '@*%1*', searchstring);

    if cust.findset then

     repeat

       insert temp record here

    .........

    repeat for each field

    (take a look to filter - @ is to make it case insensitive and * is any char, i can't remember exact syntax)

  • p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    I'd perhaps use automation or even .Net to query sql server directly. You can get your SQL server/database name from session table, use your company name to refer to correct sql table and then loop trough result of your sql query and populate temptable

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamic Search
    SELECT Name, Address, [Phone No_] FROM [CRONUS Danmark A_S$Customer]
    WHERE Name LIKE '%searchword%' or Address LIKE '%searchword%' or [Phone No_] LIKE '%searchword%'

    Ok cool, so how would you query this in nav?

  • p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    Personally I would not loop, that is too slow. I would better to create queries to populate temp table. But generally, yes.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamic Search

    So its doable? How would you manage such thing?

    Loop through etc. customer's name -> add to temp table if there are Records containing the name then Loop through Adress and add to temp table and then through phone nr. and then display the temp table?

  • p.pavuk Profile Picture
    p.pavuk 50 on at
    RE: Dynamic Search

    Not with standard NAV. Doable by developing a custom search page...

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans