Results 1 to 8 of 8

Thread: How to implement checking a Table condition in listView

  1. #1
    cent Guest

    Question How to implement checking a Table condition in listView

    Hi pals,
    I am using SugarCE v 6.5.4 . In my listview of Cases module , i add a new icon inside of edit to find a popup. As shown in fig:

    Name:  doubt.png
Views: 272
Size:  12.5 KB

    for that modification add a custom code in listviewdefs.php as

    $listViewDefs ['Cases'] =
    array (
    'CASE_NOTIFICATION_C' =>
    array (
    //'type' => 'enum',
    'link' => true,
    'default' => true,
    'sortable' => false,
    'customCode' => '<a id="notification-{$ID}" title="Add Notification" onclick="javascript:window.open(\'index.php?popup_ module=true&target_module=Meetings&acase_id={$ID}& tpl=QuickCreate.tpl&return_module=Cases&return_act ion=SavedNotification&return_id={$ID}&action=Subpa nelCreates&module=Home&target_action=QuickCreate&p arent_type=Cases&parent_id={$ID}&Activities_caseno tification_button=Case Notification\',\'\',\'width=600,height=270,resizab le=0\');" style="cursorointer"><img src="dash_icons/Case_Notification.jpg" /></a>',
    ),

    This modification is used for the purpose of add a schedule meeting easily in popup. My current criteria is if a
    schedule meeting already assigned for a record then I don't need to add a new one. I know how to
    take that query result from mysql query , but don't know how to apply i listview . please help me with a solution.

    Thanks,
    Anes

  2. #2
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: How to implement checking a Table condition in listView

    hi

    you may use logic hook process_record where you will find out - is there meeting assigned for the record
    if no - inject your icon. can populate some flag field in logic hook and use it in your customCode as {$FLAGFIELD}

    also you may use <span> inside hook to make link colored with "red" if no meetings is assigned to the record.

    kir

  3. #3
    cent Guest

    Lightbulb Re: How to implement checking a Table condition in listView

    Hi kir ,

    Your solution is fine . But I don't have idea how to set flag as you suggest . I try to remove that element using jQuery .The Script comes in front end but it's not work actually.
    my logic_hook working file content is :

    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class AvoidNotification {
    // Logic hook (beforeSave or afterSave) function of cases
    function avoid_notification ($bean, $event, $arguments) {
    global $current_user,$db;
    $user_id = $current_user->id;
    $query = "SELECT parent_id,count(*) as occurrence FROM meetings WHERE parent_id='$bean->id'";
    $res = $db->query($query);
    $row = $db->fetchByAssoc($res);


    if($row['occurrence']) {
    echo '<script>alert("fff");</script>';
    $parent_id = $row['parent_id'];
    echo '<script>$(\'a#notification-'.$parent_id.'\').remove();</script>';

    }


    }
    }

    all are fine , but the output is not get . Please advise me a solution.

    Thanks,
    Anes

  4. #4
    kir
    kir is offline Sugar Community Member
    Join Date
    Nov 2011
    Posts
    702

    Default Re: How to implement checking a Table condition in listView

    Quote Originally Posted by cent View Post
    Hi kir ,

    Your solution is fine . But I don't have idea how to set flag as you suggest . I try to remove that element using jQuery .The Script comes in front end but it's not work actually.
    my logic_hook working file content is :

    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    class AvoidNotification {
    // Logic hook (beforeSave or afterSave) function of cases
    function avoid_notification ($bean, $event, $arguments) {
    global $current_user,$db;
    $user_id = $current_user->id;
    $query = "SELECT parent_id,count(*) as occurrence FROM meetings WHERE parent_id='$bean->id'";
    $res = $db->query($query);
    $row = $db->fetchByAssoc($res);


    if($row['occurrence']) {
    echo '<script>alert("fff");</script>';
    $parent_id = $row['parent_id'];
    echo '<script>$(\'a#notification-'.$parent_id.'\').remove();</script>';

    }


    }
    }

    all are fine , but the output is not get . Please advise me a solution.

    Thanks,
    Anes
    hi

    your qeury is not correct according task
    you need to use process_record logic hook (not before or after save)
    notice that $bean in listview will be a $focus - countains just set of fields

    PHP Code:
    .....

    global 
    $current_user$db;
    $bean->user_id $current_user->id;
    $id $bean->id;
    $res $bean->db->getOne("SELECT COUNT(name) FROM meetings WHERE parent_id = $id AND deleted = 0"); 
    if $res>0 - there at least one related meeting to current record
    so add your code

    kir
    Last edited by kir; 2013-01-23 at 01:55 PM.

  5. #5
    povd is offline Member
    Join Date
    Feb 2009
    Posts
    15

    Default Re: How to implement checking a Table condition in listView

    My Solution might be a bit of an overkill but i think it should work.... mind you i havent tested it myself, but have used this for other reasons

    in your cases.php overwrite the create_new_list_query function
    PHP Code:
    function create_new_list_query($order_by$where,$filter=array(),$params=array(), $show_deleted 0,$join_type=''$return_array false$parentbean null$singleSelect false){
            
    $ret_array parent::create_new_list_query($order_by$where$filter$params$show_deleted$join_typetrue$parentbean$singleSelect);
            global 
    $db;
     
            
    $ret_array['select'] .= " meetings.id as meeting_id";

            
    $ret_array['from'] .= " LEFT JOIN meetings ON (cases.id = meetings.parent_id and meetings.deleted = 0) ";

            
    $ret_array['where'] .= $this->get_search_filters_query();

            if ( !
    $return_array )
                    return  
    $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
            return 
    $ret_array;

    and add the following field definition in vardefs:
    PHP Code:
       'meeting_id' =>
       array (
        
    'name' => 'meeting_id',
        
    'vname' => 'LBL_MEETING_ID',
        
    'type' => 'id'// or can be varchar...
        
    'source' => 'non-db',
        
    'comment' => 'dummy field for meeting id, doesnt store real data',
       ), 
    However this will return multiple rows per case if a case has more than one meeting which is possible in theory.

    this would basically give you access to a field meeting_id in listviewdwfs.php here you can access it same way as any other field in the module so in custom code area in between {php}{/php} you can do pretty much anything...

    There is also a possibility to get an id of a meeting using just the vardefs, and using the link type of field... but that was never relieble for me especially when the relationship is one to many

  6. #6
    cent Guest

    Lightbulb Re: How to implement checking a Table condition in listView

    Hi Povd & kir,

    Povd -> your solution is not relevent for me , because i need to show all in listing those have meeting , but just hide or disable the icon as i marked

    Kir -> Your solution to modify the query is excellent , but when I check my "process_load" hook it work in Home page too . please see my home page preview:

    Name:  Home page.png
Views: 228
Size:  112.2 KB

    My Required listing page is :
    Name:  listing page.png
Views: 209
Size:  22.0 KB

    In home page the listing is a dashlet . Please provide a solution to restrict that hook only on the ListView .

    Thanks,
    Anes

  7. #7
    povd is offline Member
    Join Date
    Feb 2009
    Posts
    15

    Default Re: How to implement checking a Table condition in listView

    Quote Originally Posted by cent View Post
    Hi Povd & kir,

    Povd -> your solution is not relevent for me , because i need to show all in listing those have meeting , but just hide or disable the icon as i marked
    Well what my solution does is: it gives you everything that you had in your listview plus it gives you an extra field which is meeting_id and then you can use the meeting_id to work out whether to enable or disable the link. So you just check whether meeting id is blank or has a value and based on that enable or disable the link

  8. #8
    cent Guest

    Exclamation Re: How to implement checking a Table condition in listView

    Hi Povd,
    I try to implement your solution but got a fatal error , when I copy/paste your code in my case.php file
    as shown below:
    Name:  error msg.PNG
Views: 207
Size:  32.9 KB

    Please help me with a solution.

    Thanks,
    Anes

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 2012-11-19, 04:51 PM
  2. Replies: 0
    Last Post: 2012-02-21, 06:30 PM
  3. Condition checking in (if / else) in Listview.html
    By dsuvankar in forum Developer Help
    Replies: 2
    Last Post: 2011-06-15, 06:24 AM
  4. Custom condition in listview
    By nanduruchi in forum Developer Help
    Replies: 6
    Last Post: 2010-12-01, 04:40 AM
  5. Urgent- listview condition
    By nanduruchi in forum Developer Help
    Replies: 4
    Last Post: 2010-11-27, 11:15 AM

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
  •