custom autocomplete lookup on related field

We came across a requirement where client wanted custom autocomplete lookup so after much searching , We found a way to do this.

Steps are as below,

Step 1 : Copy your < desired_module > editviewdefs.php file to custom/modules/< desired_module >/metadata/editviewdefs.php

<?php

$viewdefs['<desired_module>']['EditView']['templateMeta']['includes'] =
    array (
        array (
        'file' => 'custom/modules/<desired_module>/js/editview.js',
        ),
    );
?>

Step 2 : Add the JavaScript file you want to include into the location you referenced above(custom/modules/<desired_module>/js/editview.js).

Step 3 : Write following code in editview.js file.

SUGAR.util.doWhen(
  "typeof(sqs_objects) != 'undefined' && typeof(sqs_objects['EditView_[relate field name]']) != 'undefined'",
  functionQS
);

function functionQS()
{
sqs_objects['EditView_[relate field name]']={
    "form":"EditView",
    "method":"query",
    "modules":["[module name]"],
    "group":"or",
    "field_list":["name", "id"],
    "populate_list":["[name of relate field name","[name of hidden relate field id"],
    "required_list":["parent_id"],
    "conditions":[
       {"name":"name","op":"contains","value":""} // this can be contains, like_custom, equal, and you can add "begin" or "end" keys with % for sql search
    ],
    "order":"name",
    "limit":"30",
    "no_match_text":"No Match"
};
}

Note :

1. Read the comments in code carefully and replace the variables as asked.
2. Here, <desired_module> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.

Hope this helps and feels like missing piece is just found!

Feel free to drop your comments.

Your valuable feedback means a lot.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *