OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM Delete a field

This topic contains 8 replies, has 2 voices, and was last updated by  jaime.du 6 years ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #30838

    jaime.du
    Participant

    Hi guys,

    I’m trying to remove the field ‘Fax’ from ‘sales_lead’ by migrations script:

    Then run php app/console oro:migration:load –force –show-queries. I thought it will do the same as I add a new column. But seems like it doesn’t change the entity config because I get error Unknown column ‘o0_.fax’ in ‘field list’. It still tries to retrieve this column.
    Right now all I can do is extending the contact bundle and overwrite the view and update page. But I also need to disable it in search and API json schema. Any instruction how to remove a column in entity completely?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #30839

    Yurii Muratov
    Participant

    Hello, @jaime.du.

    Fax – is the system field of the Contact entity. So, it is no easy way to remove it from the system.

    One thing i can advise to you is to hide this field.

    To do this, you have to rewrite contact form type, contact templates.

    To hide the fax column from the datagrid you can create grid listener and remove the fax column from it. An example of such listener you can find here https://github.com/oroinc/OroCalendarBundle/blob/master/EventListener/Datagrid/SystemCalendarGridListener.php#L48, and how to correct add this class as datagrid listener: https://github.com/oroinc/OroCalendarBundle/blob/master/Resources/config/services.yml#L333.

    To remove the fax field from the search index, you can create mapping search listener and remove the fax field from the contact entity mapping. You can look at https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/SecurityBundle/EventListener/SearchListener.php#L37 as example.

    To hide the fax field from JSON API, you can add api.yml in your bundle and hide the fax field for the Contact entity:

    After that, you have to run app/console oro:api:cache:clear command to warmap the API cache.
    More info about this parameter you can find here: https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/ApiBundle/Resources/doc/configuration.md#fields-configuration-section

    #30840

    jaime.du
    Participant

    Hello @Yurii Muratov

    I tried to create an event listener to remove the column but not working. Could you enlighten me where I went wrong?

    Add it in service.yml:

    Yet I can still see it in the filter and system config tab.

    Also I tried to hide it from the API json, not working neither:

    And I clear the API cache, but I can still see it from API request result in sandbox.
    GET /api/rest/{version}/contacts.{_format}

    #30841

    Yurii Muratov
    Participant

    Hello, @jaime.du.

    What grid still have a fax column?
    Please try to clear cache if you work in prod environment.

    An example that i give to you how to hide fax column from API is for JSON API, not for old plain API.

    To hide a fax field from old API, you have to override the postSerializeContact function at Oro\Bundle\ContactBundle\Entity\Manager\ContactApiEntityManager class and remove the fax field from $result array.

    But, please consider a possibility to use JSON API. It has much more capabilities.
    Please find more information here: https://oroinc.com/orocrm/doc/2.3/book/data-api and at JSON API specification site: http://jsonapi.org/format/

    #30842

    jaime.du
    Participant

    Hello @Yurii Muratov

    Thank you for your reply. The API issue is solved now. About the UI I mean the ‘fax’ column is still accessible from
    manage filters and grid settings on index page.

    #30843

    Yurii Muratov
    Participant

    Hello, @jaime.du.

    It seems that you work in prod environment and your listener do not exists at the container. Please try to warmap the cache and check again.

    I have test your listener and at my instance, i have no fax filter and the fax column do not exist at grid settings with your listener.

    #30844

    jaime.du
    Participant

    Hello @Yurii Muratov
    Thank you for your reply. It does seem like my listener is not registered. I ran php app/console –env=prod debug:event-dispatcher and my listener is not there. I Have cleared the cache in prod environment and still not working. Could you show me the test you did? I must have done something wrong.

    #30845

    Yurii Muratov
    Participant

    Hello, @jaime.du.

    I just has add your class to some of Oro bundles and add the listener declaration.

    After that i have check the Contacts grid page:

    #30846

    jaime.du
    Participant

    Hello @Yurii Muratov

    Thanks again for your help. My dev manager helps me figure out that it’s my file structure issue. It’s working now.

Viewing 8 replies - 1 through 8 (of 8 total)

The forum ‘OroCRM’ is closed to new topics and replies.

Back to top