Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A workflow that assigns invoices to the current user after saving
#1
I have this workflow custom function in place:

PHP Code:
function updateInvoiceAssignedTo($entity) {
    global 
$adb,$default_charset,$log,$current_user;

    list(
$invoice,$invoice_crm_id) = explode('x',$entity->data['id']);  // separate webservice ID
    
if (getSalesEntityType($invoice_crm_id)=='Invoice') {

        
// Get the current user from the session
        
$user = new Users();
        
$user->retrieveCurrentUserInfoFromFile($_SESSION['authenticated_user_id']);

        
// list($usr,$usr_id) = explode('x', $entity->data['assigned_user_id']);
        
$query 'UPDATE vtiger_crmentity SET smownerid=? WHERE crmid=?';
        
$params = array($user->id$invoice_crm_id);
        
$adb->pquery($query$params);
    }


But not able to test it, would the getting of the current user ID work by getting it from the session?
Reply
#2
Workflow custom functions are executed immediately on the save event and at that moment the $current_user variable contains the user launching the save. Although I think the code you have is correct and should work correctly because the session variable must also contain the current user id, you can use the $current_user object.

$current_user->id

and even just the session variable directly, there is no need to go through the trouble of creating the user object and the extra database queries

$params = array($_SESSION['authenticated_user_id'], $invoice_crm_id);

I'd say it will work.
Joe
TSolucio
Reply
#3
Weird, that's also not working. I can't seem to default the invoice to the user that creates it. Must be doing something wrong, but what...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)