Hi Alan,<br><br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">$newProject = Project::getInstance('Project');<br></blockquote><div> </div>
<div>This is vtlib API to administer the module fields/blocks etc...will not help in creating module records.<br><br>Easy way to create module records (5.1.0 onwards), is using Server Side Webservice API<br><br><span style="font-family: courier new,monospace;">include_once 'include/Webservices/Create.php';</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">global $current_user;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">$parameters = array( 'fieldname1' => 'fieldvalue1', 'fieldname2' => 'fieldvalue2' );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$parameters['assigned_user_id'] = sprintf( '19x%s', $current_user->id ); <br>// 19 - Webservice entity id for module Users</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"><br>$resultRecord = vtws_create( 'ModuleName', $parameters, $current_user );</span><br></div><br><div class="gmail_quote">On Tue, Aug 24, 2010 at 11:09 PM, Alan Lord (News) <span dir="ltr"><<a href="mailto:alanslists@gmail.com">alanslists@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On 21/08/10 11:27, Prasad wrote:<br>
<snip /><br>
<div class="im">> Keep us posted with your experiments.<br>
<br>
</div>Hey, I bet you wish you never asked!<br>
<br>
I'm struggling at the stage of creating and saving a new Project<br>
object... I was thinking I should try and do this "The Right Way",<br>
rather than just writing to the db directly in my function:<br>
<br>
So, my CustomWorkflowHandler Function looks like this:<br>
<br>
require_once("modules/Project/Project.php");<br>
<br>
function Project_WorkflowTask_AutoCreateFn($entity) {<br>
<br>
// Get the information for the New Project<br>
$name = $entity->get('potentialname');<br>
$description = $entity->get('description');<br>
$budget = $entity->get('amount');<br>
$related_to = $entity->get('related_to');<br>
$assigned_to = $entity->get('assigned_user_id');<br>
<br>
// Get a new Project Object<br>
$newProject = Project::getInstance('Project');<br>
<br>
// Override the Project Module parameters with the data from the<br>
Potential<br>
$newProject->projectname = $name;<br>
$newProject->description = $description;<br>
$newProject->related_to = $related_to;<br>
$newProject->assigned_user_id = $assigned_to;<br>
<br>
$newProject->save('Project');<br>
<br>
?><br>
<br>
I've been examining the Objects I have instantiated and I know the above<br>
is *wrong*.<br>
<br>
But there doesn't seem to be a built-in method for overriding the<br>
module's properties, nor indeed, setting up some defaults like the<br>
'Module No' field (I thought initRequiredFields() in the CRMEntity class<br>
might do the trick, but it doesn't appear to make any difference).<br>
<br>
Sorry I'm being so thick.<br>
<div><div></div><div class="h5"><br>
Al<br>
<br>
<br>
--<br>
The Open Learning Centre<br>
<a href="http://www.theopenlearningcentre.com" target="_blank">http://www.theopenlearningcentre.com</a><br>
<br>
_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br>
</div></div></blockquote></div><br>