Advertisement
Guest User

vtiger Custom Workflow

a guest
Aug 25th, 2010
2,071
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2. /*+**********************************************************************************
  3.  * The contents of this file are subject to the vtiger CRM Public License Version 1.0
  4.  * ("License"); You may not use this file except in compliance with the License
  5.  * The Original Code is:  vtiger CRM Open Source
  6.  * The Initial Developer of the Original Code is vtiger.
  7.  * Portions created by vtiger are Copyright (C) vtiger.
  8.  * All Rights Reserved.
  9.  ************************************************************************************/
  10.  
  11. /**
  12.  * This method is registered with workflow as custom function to be invoked via Task.
  13.  * @param $entity Instance of class VTWorkflowEntity will be passed when workflow is being executed.
  14.  */
  15. function Project_WorkflowTask_AutoCreateFn($entity) {
  16.  
  17.     global $current_user, $adb, $log;
  18.  
  19.     $log->debug("Entering Custom Workflow Function: Create Project from (".$entity->get('moduleName').")...");
  20.     $log->info("Trigerring Potential is: ".$entity->get('id').".");
  21.  
  22.     include_once 'include/utils/CommonUtils.php';
  23.     include_once 'include/database/PearDatabase.php';
  24.  
  25.     // Get the user of the last modifier (or owner) of the entity that triggered this workflow
  26.     $id = explode("x", $entity->get('id'));
  27.     $potid = $id[1];   
  28.    
  29.     $log->info("Querying for user id (".$potid.")...");
  30.     $query = "SELECT smcreatorid, modifiedby FROM vtiger_crmentity WHERE crmid = ?";
  31.     $result = $adb->pquery($query,array($potid));
  32.    
  33.     $modby = $adb->query_result($result,0,"modifiedby");   
  34.     $creby = $adb->query_result($result,0,"smcreatorid");
  35.    
  36.     // If you want the "username" use function getUserName($id)
  37.     if ($modby == 0 ) {
  38.         // Entity not been modified so use creator's ID
  39.         $uname = getUserFullName($creby);
  40.     } else {
  41.         $uname = getUserFullName($modby);
  42.     }
  43.  
  44.     // Build the information for the new Project
  45.     $name = $entity->get('potentialname');
  46.     $description = "This Project was automatically created when Potential No. "
  47.                  . $entity->get('potential_no') . " was changed to "
  48.                  . $entity->get('sales_stage') . " by " . $uname . ".\n\n"
  49.                  . $entity->get('description');
  50.     $budget = $entity->get('amount');
  51.     $related_to = $entity->get('related_to');
  52.     $assigned_to = $entity->get('assigned_user_id');
  53.  
  54.     // Just get the current date
  55.     $date = date("Y/m/d");
  56.    
  57.     // Assemble the necessary Project fields    
  58.     $parameters = array(
  59.         'projectname' => $name,
  60.         'startdate' => $date,
  61.         'targetenddate' => $date,
  62.         'actualenddate' => $date,
  63.         'description' => $description,
  64.         'projectstatus' => '--none--',
  65.         'projecttype' => '--none--',
  66.         'progress' => '--none--',
  67.         'assigned_user_id' => $assigned_to,    
  68.         'targetbudget' => $budget,
  69.         'linktoaccountscontacts' => $related_to
  70.     );
  71.  
  72.     // Create the new Project
  73.     include_once 'include/Webservices/Create.php';
  74.     $log->info("Creating new Project: ".$parameters."...");
  75.     vtws_create('Project', $parameters, $current_user);
  76.     $log->debug("Exit Custom Workflow Function...");
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement