OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM Problem in Customizing the field values in Lead Form Type

This topic contains 9 replies, has 2 voices, and was last updated by  shreyas 7 years, 7 months ago.

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

  • Creator
    Topic
  • #30422

    shreyas
    Participant

    Hi Team,

    I need to customize the field values in During Lead Creation in (LeadType.php).so in Lead form type i have used CreateQueryBuilder to get values from DB to display as options.Here i have a requirement wherein there are 3 types of users to be displayed based on their roles in 3 different cols.(i.e Secondary Salesperson , sales manager & BDC) which have different role associated using oro_access_role which is mapped with respective user using oro_user_access_role.So i tried joining the oro_user with roles table & its giving result as expected. Here i have another requirement wherein i need to check the user logged in & using his logged in Id i need to fetch only those rows which are under him.(i.e if a Manager Logs in then he should only see the sales persons who are under him). So i have queries to do it as given below:

    This function i have used in my controller for same kind of requirement & it works perfectly fine.
    But the same way when i try it in FormType its not possible for me to get User logged Inn Id. I get some errors . So i thought that since its not extending controller but extending AbstractType i am facing issue & so tried creating an object of Lead Controller & calling a function similar to above which returns the Id’s required but it again threw an exception. I also looked at some of links on how to get context Id , But i could not make it clearly.

    Please find the links given below:
    Get User ID in Form Type

    Access Current User In form Type

    Please find the code given below for the Lead Form Type:

    In the Above code given for salesManager field i am trying to get AllUserIdsunderloggedin Mgr (right now hardcoded in code by an array of Ids) but got stuck on how to do it using the LoggedIn user concept as explained in above function getallusersidforlogin().

    Please find the LeadController.php code for Creating Lead :

    Here i also tried using the $form by using form Factory (commented in code given above) but i could not get it through this too.Please need help if any resources or suggestions on how to go further to solve this issue.
    Please find the screenshot given below of create Lead form shown:
    Screenshot of Customized Lead Creation Form

    I am also trying to find out on how to display the options similar to the one that is displayed in Owner Field (i.e can be searched & selected from options also – As shown in below image)
    OwnerDisplayField

    Please need some suggestions on how to go forward in this issue.
    Thanks & Regards,
    Shreyas S

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #30423

    Mike Kudelya
    Participant

    Hi,

    As i understood the main problem is get child user ids from lead form type. I have created decision.

    Firstly create provider:

    add it to services.yml:

    Secondly bind it to lead form, replace ‘orocrm_sales.lead.form.type’ in vendor/oro/crm/src/OroCRM/Bundle/SalesBundle/Resources/config/form.yml following code:

    And now you can use the provider inside the lead form:

    This is just the example, in real code you must create our own lead form and extend it.

    #30424

    shreyas
    Participant

    Hi Mike,

    Thanks a lot for your Quick solution again.It Worked as expected.Now i am able to get UserIds.

    I was interested in knowing how to display the Customized result(Secondary Sales person Field / BDC field) similarly to that are shown in Related Account Select Field(search for value / select from options) or Owner Field.

    Customized Select Field Display
    i needed to know how to make the above select field look like the one in Related Account Field given below:

    Related Account Select Field

    Kindly need help in providing some suggestions/sources if it is possible to display as explained .
    i tried looking @ select2 – Jquery but could not get it.
    Please find link given below for select2Jquery:
    https://select2.github.io/examples.html

    Thanks & Reagrds,
    Shreyas S

    #30425

    shreyas
    Participant

    Hi Team,

    I tried looking @ getting the Dropdown for Select field for BDC field similar to that of Related Account / Owner , But the problem faced is it is displaying all the users name & not taking the condition given in entity using the CreateQueryBuilder that has to display only selected users as discussed above which works perfectly when i don’t use this autocomplete feature.

    Please find the code attached(Lead Form Type) which i followed bit similar to the existing Account Bundle Form Type , i tried to compare & come with it. i also looked at services.yml of Account Bundle which needs the autocomplete alias to be registered in search Handler,But couldn’t get it Clearly since i am using the User Entity:

    Please check the screenshot of obtained Select Field UI for BDC below:
    Select Field Change for BDC

    I dont know exactly what i am missing here or am i going in correct approach. Kindly need some suggestions/guidance so that i can solve this issue.

    Thanks & Regards,
    Shreyas S

    #30426

    shreyas
    Participant

    Hi Team,

    I am able to get search with select option using oro_jqueryselect2_hidden wherein i am able to display users in select field box based on the roles . I tried coding similar to the one which is present in OrganizationUsersHandler.php present in location ProjDir\vendor\oro\platform\src\Oro\Bundle\UserBundle\Autocomplete & named a new file named BdcUserHandler.php which has the customized code that gives search result based on roles(here role taken as 2) But i tried using childOfLoggedUserProvider to get all User ids of logged In user but could not.& also registered in services.yml similar to that done for OrganizationUsersHandler
    Please find the code given below for BdcUserHandler.php :

    The ones which are commented for getting childUids are not working.I could not know how to register this childOfLoggedUserProvider to map with BdcUserHandler in Services.yml that is – similar to the one that was mapped with LeadType.php & working fine Done with the help of Mike’s Solution.

    Please find below the services.yml file which has registered BdcUserHandler for autocomplete search to work :

    Now in Lead Type.php located @ \vendor\oro\crm\src\OroCRM\Bundle\SalesBundle\Form\Type\LeadType.php
    i have added autocomplete alias as bdc_users which is defined in services.yml of User Bundle as shown above:

    Please find the LeadType.php In SalesBunle code sample where changes have been done:

    Please find the screenshot given below wherein the roles logic is working fine with search & Select Option Field implementation But i am stuck again in getting ChildUser ids for Logged In Users.

    Customized Field with Search & select options

    Kindly need some suggestions on how to go about with it to get ChildUser ids for Logged In User in BdcUserHandler. Any Resources/guidance would be very helpful:

    Thanks & Regards,
    Shreyas S

    #30427

    shreyas
    Participant

    Hi Team,

    It worked for me getting the UserIds. In Services.yml i sent a second parameter to search_handler i.e @custom_oro.child.logged.user.provider for setSecurityFacade function of Search Handler.Their i used ChildOfLoggedUserProvider object to retrieve ids similar to one done in LeadType.

    Please find the services.yml file in loc (ProjDir\vendor\oro\platform\src\Oro\Bundle\UserBundle\Resources\config) given below:

    here u can notice to setSecurityFacade in bdc_search_handler i have added another parameter called @custom_oro.child.logged.user.provider

    Please find the BdcUserHandler.php file written in location ProjDir\vendor\oro\platform\src\Oro\Bundle\UserBundle\Autocomplete given below:

    Thanks a lot for your Support team & special thanks to MIKE for helping me with the Solution to this Problem.

    Thanks & Regards,
    Shreyas S

    #30428

    Mike Kudelya
    Participant

    Hi,

    I’m not recommended you creating new custom files inside vendor directory. Is better way to create src/[Custom Namespace] and working (extend/override) there.

    #30429

    shreyas
    Participant

    Hi Mike ,

    Thanks for the Suggestion. i will place it in a custom bundle itself.

    i am just curious & interested in knowing how does it impact the system /( why is it bad practice) if we add custom files inside vendor directory.

    Thanks & Regards,
    Shreyas S

    #30430

    Mike Kudelya
    Participant

    For example for this.

    #30431

    shreyas
    Participant

    Thanks Mike for the example . i got it.

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

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

Back to top