Initial add of defaria.com
[clearscm.git] / defaria.com / blogs / Status / archives / week_2006_10_29.html
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">
4 <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6    <meta name="generator" content="Movable Type 5.2.3" />
7
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"$>" />
11
12    <title>Status for Andrew DeFaria: October 29, 2006 - November  4, 2006 Archives</title>
13
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" />
17 </head>
18 <body class="layout-one-column">
19    <div id="container">
20       <div id="container-inner" class="pkg">
21
22          <div id="banner">
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>
26             </div>
27          </div>
28
29          <div id="pagebody">
30             <div id="pagebody-inner" class="pkg">
31                <div id="alpha">
32                   <div id="alpha-inner" class="pkg">
33                      
34                      <p class="content-nav">
35                         <a href="http://defaria.com/blogs/Status/archives/week_2006_10_22.html">&laquo; 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 &raquo;</a>
38                      </p>
39                      
40                      
41                      
42
43                      <h2 class="date-header">November  3, 2006</h2>
44                      <a id="a000589"></a>
45                      <div class="entry" id="entry-589">
46                         <h3 class="entry-header">Convertdb</h3>
47                         <div class="entry-content">
48                            <div class="entry-body">
49                               <ul>
50   <li>Converted UK Users -> GPDB</li>
51
52   <li>Converted UK Sites -> GPDB</li>
53 </ul
54                               
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>
57                                  
58                                  
59                               </p>
60                            </div>
61                         </div>
62                      </div>
63                      
64                      
65
66                      <h2 class="date-header">October 31, 2006</h2>
67                      <a id="a000588"></a>
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">
72                               <ul>
73   <li>Implemented cloning procedure for DMD/CQ</li>
74 </ul>
75                               
76                               <h3>How to clone a parent CQ record to a child</h3>
77
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>
79
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>
81
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>
83
84 <div class=code><pre>
85 my $session = $entity->GetSession;
86
87 $session->NameValue ("ParentID", $entity->GetFieldValue ("id")->GetValue);
88 </pre></div>
89
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>
91
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:
93
94 <div class=code><pre>
95 my $session = $entity->GetSession;
96
97 $session->NameValue ("ParentID", "");
98 </pre></div>
99
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>
101
102 <p>In the default value hooks for each field you want cloned place the following call:</p>
103
104 <div class=code><pre>
105 CloneField ($fieldname);
106 </pre></div>
107
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>
109
110 <p>Finally, create the following Global Script:</p>
111
112 <div class=code><pre>
113 sub CloneField {
114   my $fieldname = shift;
115     
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");
120
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.
124
125     # Get the parent record
126     my $parent = $session->GetEntity ("ChangeRequest", $parentID);
127
128     # Set the child field
129     $entity->SetFieldValue (
130         $fieldname,
131         $parent->GetFieldValue ($fieldname)->GetValue
132     );
133   } # if
134 } # CloneField
135 </pre></div>
136
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>
138                               
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>
141                                  
142                                  
143                               </p>
144                            </div>
145                         </div>
146                      </div>
147                      
148                   </div>
149                </div>
150             </div>
151          </div>
152       </div>
153    </div>
154 </body>
155 </html>