Custom Javascript Function on DateTime Field

Hello Folks,

Its nice to be here. Thanks to Sugar for being so closed to their Community.

I am stuck in middle of one functionality requiring javascript onchange function on datetime field.

It involves some calculation and autofilling other fields based on this. I have found some old threads 

regarding this challenge but could not get much out of it.

Hey Sugar Heroes, please help me out on this. Any help would be appreciated.

Many Thanks.

Hats.
Parents
  • Sorry I should have said you need to do a repair after editing the file

    Don't  edit  /include/SugarFields if you need to change thes files you can create a new one in custom/include/Sugarfields but it shouldn't be necessary

    If after doing a repair and it still doesn't workt hen test it by putting something like alert(0) in your onchange to see if is being called

    What version of Sugar are you using this technique certainly works in 6.5

    Can you post the code from your editviewdefs file so I can have a look at whats wrong
  • Hi to all .. 
    I have don this part .. I have made the changes  and now I have onchange Datepicer  working..

    I have a problem to call php function from the javascript file....  
    I need to do , when I change the date , it need to make update in currency table..:)
    Pls. help some one..
    ---------------------------------------------------------------------------------------------------
    getCurrency.js  :

    function getDateCurrency(){
      
       var the_string =document.getElementById('invoice_date').value;

        jQuery.ajax({
            type: "POST",        
            url: 'http://localhost/testDima/modules/AOS_Invoices/Dima1.php',
            //dataType: 'json',
            //data: {functionname: 'getCurr', arguments: [the_string]}, 
            data: { arguments: the_string},
             success:function(data) {
             alert(data); 
             }
        });
    }

    ---------------------------------------------------------------------------------------------------

    Dima1.php

    <?php

    if (isset($_POST)) { 

        $aResult = array();
        
        if( !isset($_POST['functionname']) ) { $aResult['error'] = 'No function name!'; } 

        if( !isset($_POST['arguments']) ) { $aResult['error'] = 'No function arguments!'; }

        if( !isset($aResult['error']) ) {

            switch($_POST['functionname']) {
          
                case 'getCurr': 

                $aResult['result'] = GetCurrencyRate($_POST['arguments']);
               // $aResult['result'] = GetCurrencyRate();

                echo ($aResult);
                   break;

                default:
                   $aResult['error'] = 'Not found function '.$_POST['functionname'].'!';
                   break;
            }

        }

       echo json_encode($aResult);

    } else {

        echo ("Nothing send");
    }

       
    function GetCurrencyRate($datum){
          
         $db = DBManagerFactory::getInstance();
         $query = "SELECT iso4217,re_rate FROM currency_rates WHERE date_entered= CURDATE()";
            $result = $db->query($query); 
        while ($row = $db->fetchByAssoc($result))
                {
                  $db = DBManagerFactory::getInstance();             
                  $query = "Update currencies set conversion_rate='".$row['re_rate']."' where iso4217= '" . $row['iso4217'] . "'";
                  $db->query($query);
                }
    }

    ?>
    --------------------------------------------------------------------------------------------------------------------
    Pls. help me whit this one..  
    Thank you  all..





Reply
  • Hi to all .. 
    I have don this part .. I have made the changes  and now I have onchange Datepicer  working..

    I have a problem to call php function from the javascript file....  
    I need to do , when I change the date , it need to make update in currency table..:)
    Pls. help some one..
    ---------------------------------------------------------------------------------------------------
    getCurrency.js  :

    function getDateCurrency(){
      
       var the_string =document.getElementById('invoice_date').value;

        jQuery.ajax({
            type: "POST",        
            url: 'http://localhost/testDima/modules/AOS_Invoices/Dima1.php',
            //dataType: 'json',
            //data: {functionname: 'getCurr', arguments: [the_string]}, 
            data: { arguments: the_string},
             success:function(data) {
             alert(data); 
             }
        });
    }

    ---------------------------------------------------------------------------------------------------

    Dima1.php

    <?php

    if (isset($_POST)) { 

        $aResult = array();
        
        if( !isset($_POST['functionname']) ) { $aResult['error'] = 'No function name!'; } 

        if( !isset($_POST['arguments']) ) { $aResult['error'] = 'No function arguments!'; }

        if( !isset($aResult['error']) ) {

            switch($_POST['functionname']) {
          
                case 'getCurr': 

                $aResult['result'] = GetCurrencyRate($_POST['arguments']);
               // $aResult['result'] = GetCurrencyRate();

                echo ($aResult);
                   break;

                default:
                   $aResult['error'] = 'Not found function '.$_POST['functionname'].'!';
                   break;
            }

        }

       echo json_encode($aResult);

    } else {

        echo ("Nothing send");
    }

       
    function GetCurrencyRate($datum){
          
         $db = DBManagerFactory::getInstance();
         $query = "SELECT iso4217,re_rate FROM currency_rates WHERE date_entered= CURDATE()";
            $result = $db->query($query); 
        while ($row = $db->fetchByAssoc($result))
                {
                  $db = DBManagerFactory::getInstance();             
                  $query = "Update currencies set conversion_rate='".$row['re_rate']."' where iso4217= '" . $row['iso4217'] . "'";
                  $db->query($query);
                }
    }

    ?>
    --------------------------------------------------------------------------------------------------------------------
    Pls. help me whit this one..  
    Thank you  all..





Children
No Data