Announcement

Collapse
No announcement yet.

Implement field autocomplete from remote source, filtered by value of another field

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • espcrm
    commented on 's reply
    By the way, I end doing this Postcode using formula. It not live data though, all it does is search through my records in another entity (RealEstate), match the City name and copy the postcode over.

  • espcrm
    commented on 's reply
    Are you by any chance trying to retrieve it from "Real Estate Property" entity/extension?! If so good luck! I be very interested in your success.

  • item
    commented on 's reply
    Hi Darkcromb, Telecastg,


    just idea : why don't use something so for retreive from related entity the zip code. ? maybe something on "load event (if exist)"
    can work only for many2one relation. like meeting->parentType

    this.ajaxGetRequest('Patient/' + this.model.get('parentId')).then(function (patient) {
    let postalCode = patient['addressPostalCode'];
    this.model.set('postalCode', postalCode )

    so after your autocomplete can work ?

  • telecastg
    commented on 's reply
    Originally posted by Darkcromb View Post
    I am trying to retrieve the zip code value from another related entity​
    Does the related entity field already exist when you are trying to create a new record ?

    If so, try making an Ajax call to retrieve that value before you trigger autocomplete. That should work.

    The key point is that you must have both values defined before triggering autocomplete: The "q" or autocomplete query string value, AND the filter value.

    Good luck !, please post the results when you solve this. Autocomplete can be very useful to make data entry a lot more User friendly and efficient.

  • Darkcromb
    replied
    Thank you for all your help telecastg item .
    For the moment, it has not been successful. Especially since I am trying to retrieve the zip code value from another related entity.
    This is getting difficult for me, but I'm not going to give up! In any case, thanks for all your advice.​

    Leave a comment:


  • telecastg
    commented on 's reply
    That is because the record does not exist yet, so the "autocompleteFilter" value is undefined.

    Trying to use autocomplete when you are creating an entity, using the value of another field in the same entity as filter is a little tricky, because in order for the query to work you need to know the value of a filter which doesn't exist yet.

    One option would be to modify the field view class client\custom\src\views\fields\varchar-autocomplete-from-api.js to wait until the value of the filter field exists, include that value in the payload for the Ajax call and then trigger autocomplete.

    In other words, fetch the value of the filter in the field view class and pass it along, instead of waiting for the service class to fetch the record and grab the filter value to prepare the query for the API call.
    Last edited by telecastg; 03-20-2023, 05:12 PM.

  • telecastg
    commented on 's reply
    That makes sense !. I only tested the code in edit mode.

  • Darkcromb
    replied
    I modified the fetchJsonFromApi function to not fetch the recordId. So the URL is valid on an existing record (edit) or a new record (create).
    I also modified the API specific q argument (+bd+du+port returns only all "port boulevard") by replacing it with "***".
    The only thing that doesn't work is retrieving the "autocompleteFilter" value.
    autocompleteFilter.val() does not seem to work.​​

    Leave a comment:


  • Darkcromb
    replied
    Thank you for your advice!
    In fact, it's the record id that was not sent in the request, simply because I was in "create" mode and not "edit", so the id doesn't exists
    So, when I edit a record, it works, I can confirm that!​

    Leave a comment:


  • telecastg
    commented on 's reply
    The error is not related to the code, the "offending" line where the error is thrown (line 25 of custom\Espo\Custom\Services\AutocompleteFromApi.ph p) is where the code is making a reference to the entity that contains the autocomplete fields and the error is triggered because the system could not find such entity record.

    I suggest that you create a test entity, copy everything just like it is posted and run some tests to make sure you have the functionality working, and then try to adapt to your own system. I used the scripts as shown and they worked fine.

    One thing that will help is if you inject $GLOBALS['log'] statements in your php classes to be able to track if the inputs are being transferred correctly from one script to another. Not sure if you are familiar with this technique, but if not this posting has some information about it:

    For those that may not be aware, the following is really useful when debugging PHP code: $GLOBALS['log']->debug('Here is my variable:', [$variable]); You just need to ensure that in your `data\config.php`, the relevant logging `level` is enabled for your output: 'logger' => [ 'path' =>

  • Darkcromb
    replied
    Even without extension, in Custom, I have the same error.

    Leave a comment:


  • item
    commented on 's reply
    constructor
    Last edited by item; 03-19-2023, 09:55 AM.

  • telecastg
    commented on 's reply
    I did not test it as an extension, I simply created the scripts in the Custom namespace and everything worked fine. I would suggest that you try testing like that first.

  • telecastg
    commented on 's reply
    Thanks

    It is not necessary to add a route entry as the Ajax call goes to a standard controller.

    This project uses the existing autoselect library in Espo. The clarification was to warn users not to try to modify relying on the standard jquery extension which is also not used in Espo.

  • Darkcromb
    replied
    wow, what a job!
    Thank you so much for sharing your work.
    For now, to test, I have integrated your fields directly into the contact entity.
    I did it as an extension.
    But as soon as I integrate the extension, I get a 500 error.​

    The logs are :
    ERROR: Slim Application Error Type: Error Code: 0 Message: Call to a member function get() on null File: C:\xampp\htdocs\CRMCD01\custom\Espo\Modules\modban \Services\AutocompleteFromApi.php Line: 25 Trace: #0 C:\xampp\htdocs\CRMCD01\custom\Espo\Modules\modban \Controllers\AutocompleteFromApi.php(52): Espo\Modules\modban\Services\AutocompleteFromApi->fetchJsonFromApi(Array) EspoCRM Forum C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ ActionProcessor.php(88): Espo\Modules\modban\Controllers\AutocompleteFromAp i->actionFetchJson(Object(Espo\Core\Api\RequestWrapp er), Object(Espo\Core\Api\ResponseWrapper)) Forum C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ RequestProcessor.php(124): Espo\Core\Api\ActionProcessor->process('AutocompleteFro...', 'fetchJson', Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) #3 C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ RequestProcessor.php(95): Espo\Core\Api\RequestProcessor->proceed(Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) #4 C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ RequestProcessor.php(62): Espo\Core\Api\RequestProcessor->processInternal(Object(Espo\Core\Api\Route), Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) Groups C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ Starter.php(86): Espo\Core\Api\RequestProcessor->process(Object(Espo\Core\Api\Route), Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) Uncategorized Groups C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Hand lers\Strategies\RequestResponse.php(43): Espo\Core\Api\Starter->Espo\Core\Api\{closure}(Object(Slim\Psr7\Request) , Object(Slim\Psr7\Response), Array) Special C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Rout ing\Route.php(384): Slim\Handlers\Strategies\RequestResponse->__invoke(Object(Closure), Object(Slim\Psr7\Request), Object(Slim\Psr7\Response), Array) Visitor Messages C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd lewareDispatcher.php(81): Slim\Routing\Route->handle(Object(Slim\Psr7\Request)) Private Messages C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd lewareDispatcher.php(81): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) Albums C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Rout ing\Route.php(341): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) #11 C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Rout ing\RouteRunner.php(84): Slim\Routing\Route->run(Object(Slim\Psr7\Request)) #12 C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd leware\RoutingMiddleware.php(59): Slim\Routing\RouteRunner->handle(Object(Slim\Psr7\Request)) CSS Examples C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd lewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process(Object(Slim\Psr7\Request), Object(Slim\Routing\RouteRunner)) #14 C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd leware\ErrorMiddleware.php(107): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Slim\Psr7\Request)) General Discussion C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd lewareDispatcher.php(147): Slim\Middleware\ErrorMiddleware->process(Object(Slim\Psr7\Request), Object(Psr\Http\Server\RequestHandlerInterface@ano nymous)) Announcements C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\Midd lewareDispatcher.php(81): Psr\Http\Server\RequestHandlerInterface@anonymous->handle(Object(Slim\Psr7\Request)) Feature Requests C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\App. php(215): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) Installation and Upgrade Help C:\xampp\htdocs\CRMCD01\vendor\slim\slim\Slim\App. php(199): Slim\App->handle(Object(Slim\Psr7\Request)) Extensions C:\xampp\htdocs\CRMCD01\application\Espo\Core\Api\ Starter.php(62): Slim\App->run() Developer Help C:\xampp\htdocs\CRMCD01\application\Espo\Core\Appl icationRunners\Api.php(45): Espo\Core\Api\Starter->start() Bug Reports C:\xampp\htdocs\CRMCD01\application\Espo\Core\Appl ication\RunnerRunner.php(87): Espo\Core\ApplicationRunners\Api->run() Unminify assets or how to recreate t...o.min.js file? C:\xampp\htdocs\CRMCD01\application\Espo\Core\Appl ication.php(78): Espo\Core\Application\RunnerRunner->run('Espo\\Core\\Appli...', NULL) C:\xampp\htdocs\CRMCD01\public\api\v1\index.php(37 ): Espo\Core\Application->run('Espo\\Core\\Appli...') #24 {main} Tips: To display error details in HTTP response set "displayErrorDetails" to true in the ErrorHandler constructor. [] []
    Attached Files

    Leave a comment:

Working...
X