bean not in if condition even logic is correct in logic hook

Hi,

a weird thing in my system

I have logic_hook in opportunities module after_save

but one record always not in a condition, I'm not sure why.

could you please suggest how should I investigate a problem?

logic: when change assignee from Admin to any user, do orange and green.

but weird not doing orange.

This logic for orange.

- is update

- assigned user id before not equal after

- not Admin

if (
        $arguments['isUpdate'] == true &&
        $arguments['dataChanges']['assigned_user_id']['before'] != $arguments['dataChanges']['assigned_user_id']['after'] &&
        $bean->assigned_user_id != 1
){
// do orange and green
}

log show:

user 1 (top) normal user

user 2 (bottom) weird user id = 1f99f0d8

Sugar 9 Pro

Thanks,

M

  • Hi Autchara Chaiprom,

    I didn't understand your situation correctly. Are you trying to say that "if condition" is hitting properly but the partial implementation in this condition is executing(For green)? Am I correct?

  • One more thing, if you are checking that record's assign must update from Admin to normal User than you must need to add one more AND condition because currently, it is also true if the record will update from a normal user as well. 

    if (
            $arguments['isUpdate'] == true &&
            
    $arguments['dataChanges']['assigned_user_id']['before'] == 1 &&
            $arguments['dataChanges']['assigned_user_id']['before'] != $arguments['dataChanges']['assigned_user_id']['after'] &&
            $bean->assigned_user_id != 1
    ){
    // do orange and green
    }
  • Hi Autchara Chaiprom

    I ´m not so sure of understand what are you doing, but, an after_save logic_hook it could execute several times. You need another kind of condition like a flag (boolean field) or something like that. In the module opportunities exist an status field, please check it, about your if condition logic, I think the Maryam Aslam answer is good, just please, I suggest you do groups of conditions and do text comparison validations for the ids like:

    example: 

    //in this if, you validate the flag field of the record
    if($arguments['<may_be_status>'] == "<some_kind_value>"){
          if
    (
               ($arguments['isUpdate'] == true
    )
                      &&
               (
    $arguments['dataChanges']['assigned_user_id']['before'] == "1")
                      &&

               ($arguments['dataChanges']['assigned_user_id']['before'] !=
                   $arguments['dataChanges']['assigned_user_id']['after'])
                   &&
               ($bean->assigned_user_id != "1")
       ){
          // do orange and green
       }else{
         //do another code here or not
       }
    }

    Remember, in SugarCRM data base the id´s values are type char. 

    I hope it helps you!

    Regards.

  • Hi all,

    This issue is solved.

    Thank you for all your help above.

    Put a quote in logic user id then it works.

    Please note that assigned_user_id is string.

    Wrong

    $bean->assigned_user_id != 1

    Correct

    bean->assigned_user_id != "1"

    Thank you again,

    M