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

Parents
  • 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?

  • 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.

Reply
  • 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.

Children
No Data