How to fetch all records from Account Module and also updating a field value in all record

Hi Folks,

I want to get All records from Accounts Module and want to do some manipulation on that data.

Once it is done then i will update the data to same record.

How to do this bulk operation read and update the all records.

Thanks in Advance

Regards

John

Parents
  • Hi Follow John

    You can do it by both ways SQLQuery or SugarQuery.

    Using SQLQuery to do so:

    follow this link.

    Using sugarQuery to do so:

    $bean = BeanFactory::getBean('Accounts');
    $query = new SugarQuery();
    $query->from($bean, array('team_security' => false));
    $query->where()->equals('deleted', '0');
    $account_list = $query->execute();     
    if ( $account_list != null ) {
       foreach ($account_list as $acct) {               
         $accounts = new Account();
         $accounts->retrieve($acct->id);
         $accounts->name = 'Updating by Ramana';
         $accounts->save();
       }
    }

    Hope this Helps..!!

    Best Regards

    S Ramana Raju

  • Hi Ramana! Sorry for the dumb question but I'm new to sugar. Can you tell me where to put this code? If I have to go through customization. 

Reply Children
  • Hi Hijab Fatima,

    Would you please explain your use case? Are you trying to fetch the data in logic hook or some custom endpoint or custom script? Based on your use case, you can include the above code script anywhere in the files written inside sugar scope. For external files, you cannot use SugarQuery class.

    Please provide us more info and we could help you.

    Regards.