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(&#39;Project&#39;);<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 &#39;include/Webservices/Create.php&#39;;</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( &#39;fieldname1&#39; =&gt; &#39;fieldvalue1&#39;, &#39;fieldname2&#39; =&gt; &#39;fieldvalue2&#39; );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">$parameters[&#39;assigned_user_id&#39;] = sprintf( &#39;19x%s&#39;, $current_user-&gt;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( &#39;ModuleName&#39;, $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">&lt;<a href="mailto:alanslists@gmail.com">alanslists@gmail.com</a>&gt;</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>
&lt;snip /&gt;<br>
<div class="im">&gt; Keep us posted with your experiments.<br>
<br>
</div>Hey, I bet you wish you never asked!<br>
<br>
I&#39;m struggling at the stage of creating and saving a new Project<br>
object... I was thinking I should try and do this &quot;The Right Way&quot;,<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(&quot;modules/Project/Project.php&quot;);<br>
<br>
function Project_WorkflowTask_AutoCreateFn($entity) {<br>
<br>
   // Get the information for the New Project<br>
   $name = $entity-&gt;get(&#39;potentialname&#39;);<br>
   $description = $entity-&gt;get(&#39;description&#39;);<br>
   $budget = $entity-&gt;get(&#39;amount&#39;);<br>
   $related_to = $entity-&gt;get(&#39;related_to&#39;);<br>
   $assigned_to = $entity-&gt;get(&#39;assigned_user_id&#39;);<br>
<br>
   // Get a new Project Object<br>
   $newProject = Project::getInstance(&#39;Project&#39;);<br>
<br>
   // Override the Project Module parameters with the data from the<br>
Potential<br>
   $newProject-&gt;projectname = $name;<br>
   $newProject-&gt;description = $description;<br>
   $newProject-&gt;related_to = $related_to;<br>
   $newProject-&gt;assigned_user_id = $assigned_to;<br>
<br>
   $newProject-&gt;save(&#39;Project&#39;);<br>
<br>
?&gt;<br>
<br>
I&#39;ve been examining the Objects I have instantiated and I know the above<br>
is *wrong*.<br>
<br>
But there doesn&#39;t seem to be a built-in method for overriding the<br>
module&#39;s properties, nor indeed, setting up some defaults like the<br>
&#39;Module No&#39; field (I thought initRequiredFields() in the CRMEntity class<br>
might do the trick, but it doesn&#39;t appear to make any difference).<br>
<br>
Sorry I&#39;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>