updateParams on custom fields

Hi there !

I want to use the updateParams function, but it doesn't work on custom fields for custom tables, for example I want to update a field named status_proc_c on the table cases_cstm, but after debugging I noticed that the field isn't considered because it has the key source and it is not of type db :

if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') {
continue;
}

Here is the code I tried to execute :

global $db;
$fieldDefs = $GLOBALS['dictionary']['Case']['fields'];
$db_return = $db->updateParams('cases_cstm',
$fieldDefs,
array(
'status_proc_c' => 'status_proc_refused'
),
array(
'id_c' => $taskBean->parent_id,
)
);


Is there a way to bypass that ? That's a pity if we can only set the values for the principal table.

I checked on this article written by Matt Marum for my searches sugarclub.sugarcrm.com/.../use-of-prepared-statements-in-sugar-7-9
Thanks in advance for your feedback !

Have a nice and safe day,

Enes

Parents
  • Enes,

    If the field you are trying to update is not of source "db" then it is going to be "non-db" which means that the field does not actually exist in the database. As it is not a real field you would not be able to update data in it via any database query, which is what the function updateParams does. That is why the function does a check to ensure the field is of source "db" as any other value makes the function useless.

    "non-db"-type fields are held in memory only - generally the values in there are set via a logic hook at read-time or by other code for display only. For example, the "account_name" field on the Contact record that can be seen in the cached vardefs and used in a record. This is not a field held in the database but the value is calculated when the record is retrieved by querying on the "account_id" value, which is held in the database.

    What is your use case for updating the value in the specified field? Is it different to the above scenarios?

    Thanks,

    JH.

  • Enes,

    Actually, I have re-read what you said and realise now that you are probably trying to set fields with a source of "custom_fields" rather than "non-db" so what I have put above probably doesn't apply.

    I would still like to know the full use case you are trying to solve here though Slight smile You may want to check out how the save() function does this task in the ./modules/DynamicFields/DynamicField.php file as well

    Thanks,

    JH.

Reply
  • Enes,

    Actually, I have re-read what you said and realise now that you are probably trying to set fields with a source of "custom_fields" rather than "non-db" so what I have put above probably doesn't apply.

    I would still like to know the full use case you are trying to solve here though Slight smile You may want to check out how the save() function does this task in the ./modules/DynamicFields/DynamicField.php file as well

    Thanks,

    JH.

Children
  • Hello John,

    Yes you're right, I'm trying to set up custom_fields source field, here is the description of my field : 

    [status_proc_c] => Array
    (
        [labelValue] => Status Procuration
        [visibility_grid] => 
        [required] => 
        [source] => custom_fields
        [name] => status_proc_c
        [vname] => LBL_STATUS_PROC
        [type] => enum
        [massupdate] => 
        [no_default] => 
        [comments] => 
        [help] => 
        [importable] => true
        [duplicate_merge] => enabled
        [duplicate_merge_dom_value] => 1
        [audited] => 1
        [reportable] => 1
        [unified_search] => 
        [merge_filter] => disabled
        [pii] => 
        [calculated] => 
        [len] => 100
        [size] => 20
        [options] => case_status_procuration
        [default] => 
        [dependency] => 
        [id] => Casesstatus_proc_c
        [custom_module] => Cases
    )

    In fact my use case is the following : 

    I have some tasks attached to a case bean, after save of each task, I need to know if they are all validated or rejected, then I will update a field in my Case Bean. I was doing that by saving the case, but it causes concurrent access with the current user from time to time.

    That's why I want to use updateParams by setting the value directly in DB.

    Regarding the DynamicFields.php file, I checked the save function but how can I apply such thing for my needs ? Should I write the same code ? 

    Thanks in advance.

    Best regards,

    Enes