1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard">
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Movable Type 5.2.3" />
8 <link rel="stylesheet" href="http://defaria.com/blogs/Status/styles-site.css" type="text/css" />
9 <link rel="alternate" type="application/atom+xml" title="Atom" href="http://defaria.com/blogs/Status/atom.xml" />
10 <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://defaria.com/blogs/Status/index.xml"$>" />
12 <title>Status for Andrew DeFaria: October 29, 2006 - November 4, 2006 Archives</title>
14 <link rel="start" href="http://defaria.com/blogs/Status/" title="Home" />
15 <link rel="prev" href="http://defaria.com/blogs/Status/archives/week_2006_10_22.html" title="October 22, 2006 - October 28, 2006" />
16 <link rel="next" href="http://defaria.com/blogs/Status/archives/week_2006_11_05.html" title="November 5, 2006 - November 11, 2006" />
18 <body class="layout-one-column">
20 <div id="container-inner" class="pkg">
23 <div id="banner-inner" class="pkg">
24 <h1 id="banner-header"><a href="http://defaria.com/blogs/Status/" accesskey="1">Status for Andrew DeFaria</a></h1>
25 <h2 id="banner-description">Searchable status reports and work log</h2>
30 <div id="pagebody-inner" class="pkg">
32 <div id="alpha-inner" class="pkg">
34 <p class="content-nav">
35 <a href="http://defaria.com/blogs/Status/archives/week_2006_10_22.html">« October 22, 2006 - October 28, 2006</a> |
36 <a href="http://defaria.com/blogs/Status/">Main</a>
37 | <a href="http://defaria.com/blogs/Status/archives/week_2006_11_05.html">November 5, 2006 - November 11, 2006 »</a>
43 <h2 class="date-header">November 3, 2006</h2>
45 <div class="entry" id="entry-589">
46 <h3 class="entry-header">Convertdb</h3>
47 <div class="entry-content">
48 <div class="entry-body">
50 <li>Converted UK Users -> GPDB</li>
52 <li>Converted UK Sites -> GPDB</li>
55 <p class="entry-footer">
56 <span class="post-footers">Posted by at 9:37 AM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000589.html">Permalink</a>
66 <h2 class="date-header">October 31, 2006</h2>
68 <div class="entry" id="entry-588">
69 <h3 class="entry-header">Cloning done</h3>
70 <div class="entry-content">
71 <div class="entry-body">
73 <li>Implemented cloning procedure for DMD/CQ</li>
76 <h3>How to clone a parent CQ record to a child</h3>
78 <p>You would think that this would be clearly documented in the CQ manual but it isn't. The requirement is clear enough - "implement parent/child relationships for a CQ record... Oh and when a child is created could you copy everything from the parent and we'll change what's different in the child".</p>
80 <p>Implementing a parent/child relationship is pretty clear and documented - basically you create a reference link in the current record back to itself. CQ even has a parent/child control that handles manipulating the relationship allowing the user the controls to link in existing records, delete a parent/child relationship or add a new record as a child of this record. But there is nothing in there about copying data from the parent to the child. This you must do with hooks. But how to code the hooks?</p>
82 <p>I found a method for doing this and implemented the following. The trick is to add pre and post hooks to the <b>New</b> button of the parent/child control. This button is selected when the user wishes to add a new child record to this parent. The pre action hook, created as a <i>Record Script</i> set a session wide variable saying "Hey I'm adding a new child record to this parent". This variable contains the ID of the parent. The following code accomplishes this:</p>
85 my $session = $entity->GetSession;
87 $session->NameValue ("ParentID", $entity->GetFieldValue ("id")->GetValue);
90 <p>After creating this record script add it as the pre-action hook for the new button. Don't forget to toggle the Enable for CQ Web (I don't really understand why you would ever not toggle that).</p>
92 <p>For the post-action script you are basically saying "Hey I'm no longer adding a new child record to this parent" with the following code:
95 my $session = $entity->GetSession;
97 $session->NameValue ("ParentID", "");
100 <p>What this does is effectively bound the time you are in this unique situation - any other time the global session variable ParentID will be blank. Now the cloning can begin...</p>
102 <p>In the default value hooks for each field you want cloned place the following call:</p>
104 <div class=code><pre>
105 CloneField ($fieldname);
108 <p>This is written as a call to a Global Script since the code will always be the same and because you'll have to do this for each field that you wish cloned.</p>
110 <p>Finally, create the following Global Script:</p>
112 <div class=code><pre>
114 my $fieldname = shift;
116 # Check session wide global, ParentID, and if set retrieve
117 # the parent record and clone this field
118 my $session = $entity->GetSession;
119 my $parentID = $session->GetNameValue ("ParentID");
121 if ($parentID ne "") {
122 # If ParentID is not blank then we are adding a subtask.
123 # Copy this field from the parent to this new child.
125 # Get the parent record
126 my $parent = $session->GetEntity ("ChangeRequest", $parentID);
128 # Set the child field
129 $entity->SetFieldValue (
131 $parent->GetFieldValue ($fieldname)->GetValue
137 <p>This script checks to see if the session global "ParentID" is not blank, indicating that we are in this special mode of adding a new child to an existing parent, and if so, gets the parent record and the field value based on the passed in field name. Finally it sets the field value based on the field name to that of the value of the corresponding parent's field value.</p>
139 <p class="entry-footer">
140 <span class="post-footers">Posted by at 11:18 AM</span> <span class="separator">|</span> <a class="permalink" href="http://defaria.com/blogs/Status/archives/000588.html">Permalink</a>