How to know if a field is audited in a module

Hi All,

           How to know if a field is audited in a module,in its logic hook

Regards

Sidhu

Tevfik Tümer Avinash Singh Bhavesh Patel

Parents
  • Hi Sidhu, 

    If it is just about checking if audit is enabled simply go to Admin > Studio > Fields and check for the audit checkbox:

    http://support.sugarcrm.com/Knowledge_Base/Studio_and_Module_Builder/Adding_Fields_to_a_Modules_Change_Log/index.html 

    Best,

    Dennis

  • Dennis Wangerin,

                                       i am aware about this,but i want to know how can we loop through the fields in a logic hook and retreive the fields which have audit as checked

    Regards

    sidhu

  • Ah ok now I see. Which version are your running? 

    In Sugar7 with Rest v10 you can use GET /metadata to receive all fields etc. In the following example I got the whole metadata for Accounts. In there you will find the fields and for each audited field you will see

     [audited] => 1
    $url = $base_url . "/oauth2/token";

    $oauth2_token_arguments = array(
        "grant_type" => "password",
        //client id/secret you created in Admin > OAuth Keys
        "client_id" => "test",
        "client_secret" => "test",
        "username" => $username,
        "password" => $password,
        "platform" => "base"
    );

    $oauth2_token_response = call($url, '', 'POST', $oauth2_token_arguments);

    //Endpoint - GET /<metadata>/

    $url = $base_url . "/metadata/";

    $record_arguments = array(
        "module_filter" => "Accounts",
    );

    $record_response = call($url, $oauth2_token_response->access_token, 'GET', $record_arguments);
  • Hi Sidhu,

    Please try below code

    class Class_logichook_custom {
        function fn_before_save($bean, $event, $arguments)
        {
            if(!empty($bean->field_name_map))
            {
                foreach($bean->field_name_map as $field_nm_arr)
                {
                    if($field_nm_arr['audited'])
                    {
                        echo $field_nm_arr['name']; echo '<br>';
                    }
                }
                exit;
            }
        }
       
    }
  • Hi Offshore Evolution

    class Class_logichook_custom {
        function fn_before_save($bean, $event, $arguments)


                 
                 $str='';
                 
                 if(!empty($bean->field_name_map))
                    {
                        foreach($bean->field_name_map as $field_nm_arr)
                        {
                            if($field_nm_arr['audited'] == 1)
                            {
                                $str .= $field_nm_arr['name']; echo '<br>';
                            }
                        }
                        
                    }
                    
                $bean->description = $str;
                
                $bean->save();

    }

    }

    worked perfect for me.

    Regards

    Sidhu

Reply
  • Hi Offshore Evolution

    class Class_logichook_custom {
        function fn_before_save($bean, $event, $arguments)


                 
                 $str='';
                 
                 if(!empty($bean->field_name_map))
                    {
                        foreach($bean->field_name_map as $field_nm_arr)
                        {
                            if($field_nm_arr['audited'] == 1)
                            {
                                $str .= $field_nm_arr['name']; echo '<br>';
                            }
                        }
                        
                    }
                    
                $bean->description = $str;
                
                $bean->save();

    }

    }

    worked perfect for me.

    Regards

    Sidhu

Children
No Data