Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to do backround query on button click

  1. #1
    vistar86 is offline Sugar Community Member
    Join Date
    Jan 2012
    Posts
    32

    Default How to do backround query on button click

    Hi i wonder if this is possible at all, i have textbox named "serial_number_c" and a submit button in edit view (both custom) and when user clicks button, i want it to check to see if the text from the "serial_number_c" value is in the table already and if so then populate some data into the editview textboxes from the record found.

    thanks in advance

  2. #2
    SagarCRM's Avatar
    SagarCRM is offline Sugar Community Member
    Join Date
    Oct 2011
    Location
    Mumbai, Maharashtra, India
    Posts
    111

    Default Re: How to do backround query on button click

    You can do this using ajax functionality on save button click
    or onblur event of textbox
    or before editview load you can store data fetched from db in variable abd can compare before saving using javascript (not recommended) .
    I have done this in one of my module on onblur event.


    keep rocking !!!
    --

    Thanks & Regards,

    Sagar Salunkhe
    Mumbai, Maharashtra, INDIA

    sagar.salunkhe1991@gmail.com

    ~~ IT professionals never dies, they just go Offline... ~~


    sugar development and support services:- indian.sugarbean@gmail.com

  3. #3
    vistar86 is offline Sugar Community Member
    Join Date
    Jan 2012
    Posts
    32

    Default Re: How to do backround query on button click

    ok this sounds good, but where to start? any pointers? when i add custom php code to editview it makes css mess up.

    do i need to add this code to editviewvardefs? or code in views/edit.view.php? or both?

    where can i code the onblur event? and example?

    do you or anyone have any examples, or link to a tutorial?

    thanks for your response.

  4. #4
    SagarCRM's Avatar
    SagarCRM is offline Sugar Community Member
    Join Date
    Oct 2011
    Location
    Mumbai, Maharashtra, India
    Posts
    111

    Default Re: How to do backround query on button click

    Quote Originally Posted by vistar86 View Post
    ok this sounds good, but where to start? any pointers? when i add custom php code to editview it makes css mess up.

    do i need to add this code to editviewvardefs? or code in views/edit.view.php? or both?

    where can i code the onblur event? and example?

    do you or anyone have any examples, or link to a tutorial?

    thanks for your response.
    Hi Vistar,
    For using javascript you have to do a lot of stuff bu my way.
    Well it starts from creating javascript file in your cutom/modules/<module_name>/EditView.js

    the file will contain code somthing like this:


    Code:
    window.onload = load;
    function load(){
    
    textboxid.onblur = function(){checkduplicate()}
    
    }
    
    function checkduplicate()
    {
    //your ajax functionality which will disable your save button if serial number is duplicated
    }
    then you have to include your javascript file in your editviewdefs.php

    it will look something like this

    PHP Code:
        'templateMeta' => 
        array (
          
    'includes' => 
          array (
            
    => 
            array (
              
    'file' => 'custom/modules/<module_name>/EditView.js',
            ),
          ),
          
    'maxColumns' => '2',
          
    'form' => 
    hope this will be helpfull..

    Keep rocking !!!
    --

    Thanks & Regards,

    Sagar Salunkhe
    Mumbai, Maharashtra, INDIA

    sagar.salunkhe1991@gmail.com

    ~~ IT professionals never dies, they just go Offline... ~~


    sugar development and support services:- indian.sugarbean@gmail.com

  5. #5
    vistar86 is offline Sugar Community Member
    Join Date
    Jan 2012
    Posts
    32

    Default Re: How to do backround query on button click

    That does not seem to work for me, i'm using sugar 6.1 and both module and fields are custom.

    heres what i did:

    stuck this in custom/modules/GBM_Repairs/editView.js

    PHP Code:
    window.onload load;
    function 
    load(){

    serial_number_c.onblur = function(){checkduplicate()}

    }

    function 
    checkduplicate()
    {
    alert('works');


    and heres my editviewdefs.php:

    PHP Code:
    $module_name 'GBM_Repairs';
    $_object_name 'gbm_repairs';
    $viewdefs[$module_name]['EditView'] = array(


        
    'templateMeta' => array('maxColumns' => '2'
                                
    'widths' => array(
                                                array(
    'label' => '10''field' => '30'), 
                                                array(
    'label' => '10''field' => '30')
                                                ), 
                                                
                                                
                                                
    'includes' => 
                                                array (
                                                
    => 
                                                array (
                                                
    'file' => 'custom/modules/GBM_Repairs/EditView.js',
                                                ),
                                                ),           
                                                
                                                ),
          
                                                
     
    'panels' =>array (
      
    'default' => 
      array (
        
        array (
          
          array (
            
    'name' => $_object_name '_number',
            
    'type' => 'readonly',
          ),
          
    'assigned_user_name',
        ),
        
        array (
          
    'priority',
        ),
        
        array (
          
    'resolution',
          
    'status',
        ),

        array (
          array(
    'name'=>'name''displayParams'=>array('size'=>60)),
        ),
        
        array (
          
    'description',
        ),
        
        
        array (
          
    'work_log',
        ),
      ),
                                                        
    ),
                            
    ); 
    can you point out where i'm going wrong, i am in developer mode also.

  6. #6
    SagarCRM's Avatar
    SagarCRM is offline Sugar Community Member
    Join Date
    Oct 2011
    Location
    Mumbai, Maharashtra, India
    Posts
    111

    Default Re: How to do backround query on button click

    Hi vistar,
    your code should be something like this,

    PHP Code:

        
    'templateMeta' => array(
                            
    'includes' => 
                            array (
                            
    => 
                            array (
                            
    'file' => 'custom/modules/GBM_Repairs/EditView.js',
                            ),
                                               ),
                            
    'maxColumns' => '2'
                                
    'widths' => array(
                                                array(
    'label' => '10''field' => '30'), 
                                                array(
    'label' => '10''field' => '30')
                                                ), 
                                                ),           
                                                
                            ), 
    hope this will work fine

    Keep rAwKing!!!
    Last edited by SagarCRM; 2012-01-12 at 08:32 AM. Reason: writing mistake in code
    --

    Thanks & Regards,

    Sagar Salunkhe
    Mumbai, Maharashtra, INDIA

    sagar.salunkhe1991@gmail.com

    ~~ IT professionals never dies, they just go Offline... ~~


    sugar development and support services:- indian.sugarbean@gmail.com

  7. #7
    vistar86 is offline Sugar Community Member
    Join Date
    Jan 2012
    Posts
    32

    Default Re: How to do backround query on button click

    heres my new editviewdefs.php:

    PHP Code:

    $module_name 
    'GBM_Repairs';
    $_object_name 'gbm_repairs';
    $viewdefs[$module_name]['EditView'] = array(


        
    'templateMeta' => array(
                            
    'includes' => 
                            array (
                            
    => 
                            array (
                            
    'file' => 'modules/GBM_Repairs/EditView.js',
                            ),
                                               ),
                            
    'maxColumns' => '2'
                                
    'widths' => array(
                                                array(
    'label' => '10''field' => '30'), 
                                                array(
    'label' => '10''field' => '30')
                                                ), 
                                                ),           
                                                
                            ),  
          
                                                
     
    'panels' =>array (
      
    'default' => 
      array (
        
        array (
          
          array (
            
    'name' => $_object_name '_number',
            
    'type' => 'readonly',
          ),
          
    'assigned_user_name',
        ),
        
        array (
          
    'priority',
        ),
        
        array (
          
    'resolution',
          
    'status',
        ),

        array (
          array(
    'name'=>'name''displayParams'=>array('size'=>60)),
        ),
        
        array (
          
    'description',
        ),
        
        
        array (
          
    'work_log',
        ),
      ),
                                                        
    ),
                            
    ); 
    and my EditView.js:

    PHP Code:
    window.onload load;
    function 
    load(){

    serial_number_c.onblur = function(){checkduplicate()}

    }

    function 
    checkduplicate()
    {
    alert('works');

    It's still not doing anything???

    i just realised too, as this is javascript, how am i supposed to query database in JS?? is that possible...

  8. #8
    SagarCRM's Avatar
    SagarCRM is offline Sugar Community Member
    Join Date
    Oct 2011
    Location
    Mumbai, Maharashtra, India
    Posts
    111

    Default Re: How to do backround query on button click

    where your javascript file situated in???????
    is it in custom module directory or in module directory????

    PHP Code:
     'file' => 'modules/GBM_Repairs/EditView.js'
    if its situated in custom folder it'll be like

    PHP Code:
     'file' => 'custom/modules/GBM_Repairs/EditView.js'
    you have to call AJAX in javascript
    --

    Thanks & Regards,

    Sagar Salunkhe
    Mumbai, Maharashtra, INDIA

    sagar.salunkhe1991@gmail.com

    ~~ IT professionals never dies, they just go Offline... ~~


    sugar development and support services:- indian.sugarbean@gmail.com

  9. #9
    vistar86 is offline Sugar Community Member
    Join Date
    Jan 2012
    Posts
    32

    Default Re: How to do backround query on button click

    i'm working in modules directory directly, i'm not updating the system so this shouldn't be an issue.

    Looking through firebug, the JS is not even being called in editView.

    does it have to be done in custom directory for it to work?

    i've never coded in Ajax, so is there any other way to do it in PHP or javascript?

    thanks for your responses, much appreciated pal.
    Last edited by vistar86; 2012-01-12 at 11:25 AM.

  10. #10
    SagarCRM's Avatar
    SagarCRM is offline Sugar Community Member
    Join Date
    Oct 2011
    Location
    Mumbai, Maharashtra, India
    Posts
    111

    Default Re: How to do backround query on button click

    Well I'm newbie in Sugar, So i do prefer ajax for such cases, you can include javascript file in another way too...

    in edit view.edit.php

    PHP Code:
        function display(){
            
         
    $javascript file_get_contents('custom/modules/<module_name>/EditView.js');
        echo 
    $javascript
    the file will contain same javascript file as above adding <script> snippet

    PHP Code:
    <script type="text/javascript">

    window.onload load;
    function 
    load(){

    serial_number_c.onblur = function(){checkduplicate()}

    }

    function 
    checkduplicate()
    {
    alert('works');
    }  

    </script> 
    --

    Thanks & Regards,

    Sagar Salunkhe
    Mumbai, Maharashtra, INDIA

    sagar.salunkhe1991@gmail.com

    ~~ IT professionals never dies, they just go Offline... ~~


    sugar development and support services:- indian.sugarbean@gmail.com

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PHP script call on button click
    By aureh12 in forum Developer Help
    Replies: 8
    Last Post: 2010-11-29, 10:39 AM
  2. call a function on a click of button
    By prince.pandey7 in forum Developer Help
    Replies: 0
    Last Post: 2010-08-05, 06:50 AM
  3. CancelSale button click on sales tab
    By aswini in forum Help
    Replies: 4
    Last Post: 2010-03-29, 11:37 AM
  4. Click button and open new window
    By giacomo.cosenza in forum Developer Help
    Replies: 0
    Last Post: 2010-03-16, 11:24 AM
  5. how to create pop-up on click of select button
    By jenifer in forum Developer Help
    Replies: 2
    Last Post: 2008-07-16, 12:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •