Hide
Siafoo is here to make coding less frustrating and to save you time. Join Siafoo Now or Learn More

Leads Activity Report using SharePoint Data Zoom Extension for salesforce.com Atom Feed 0

In Brief This snippet create a Leads Activity report from salesforce.com leads data. The SharePoint Data Zoom Web Part extension for salesforce.com is required.... more
# 's
  1## SalesForce Leads Activity v1.0
2## by SharePoint Solutions
3
4## Get search inputs
5#set( $id = $queryString.get_item("id") )
6#set( $searchCriteria = $form.get_item("searchCriteria") )
7#set( $searchType = $form.get_item("searchType") )
8#set( $rolodex = $form.get_item("rolodex") )
9
10## More global variables
11#set( $minOpp = -120 )
12#set( $maxOpp = $minOpp * -1 )
13#set( $periods = [ $minOpp, -90, -60, -30, -14, -7, 0 ] )
14#set( $leadsQuery = "CreatedDate = LAST_N_DAYS:${maxOpp}" )
15#set( $leadsOrderBy= "CreatedDate DESC" )
16
17## Get paging attributes
18#set( $pageIndex = $Strings.ConvertToInt($form.get_item("pageIndex"), 0) )
19#set( $pageSize = $Strings.ConvertToInt($form.get_item("pageSize"), 100) )
20
21## Add filter terms
22#if( !$Strings.IsNullOrEmpty($id) && $request.HttpMethod == "GET" )
23
24 ##set( $searchFilter = $leadsQuery )
25 ##set( $searchType = "Id" )
26
27#elseif( !$Strings.IsNullOrEmpty($rolodex) )
28
29 #if( $rolodex == "All" )
30 #set( $searchFilter = $leadsQuery)
31 #set( $searchCriteria = "" )
32 #else
33 #set( $searchFilter = "OwnerId = '${rolodex}' AND ${leadsQuery}" )
34 #set( $searchCriteria = "${rolodex}" )
35 #set( $searchType = "LastName" )
36 #end
37
38#elseif( !$Strings.IsNullOrEmpty($searchCriteria) )
39
40 #set( $searchFilter = "$searchType Like '%${searchCriteria}%' AND ${leadsQuery}" )
41#else
42 #set( $searchFilter = $leadsQuery )
43#end
44
45## Get users
46
47## Setup user properties to fetch
48#set( $user_properties = ["Id", "Name"] )
49
50#set( $sfaUsers = $ApexUsers.GetUsers( "IsActive = TRUE", "LastName", 0, 1000, $user_properties ) )
51
52#set( $ctx_id = $form.get_item("cid") )
53
54<script>
55<!--
56
57var users = new Array();
58function addUser(id,name)
59{
60 users[id] = name;
61}
62
63
64function applySearch()
65{
66 document.getElementById("pageIndex").value = "0";
67 document.getElementById("rolodex").value = "";
68 theForm.submit();
69}
70
71function setPageSize()
72{
73 document.getElementById("pageIndex").value = "0";
74 theForm.submit();
75}
76
77function gotoPageIndex(pageIndex)
78{
79 document.getElementById("pageIndex").value = pageIndex;
80 theForm.submit();
81}
82
83function gotoRolodex(rolodex)
84{
85 document.getElementById("pageIndex").value = "0";
86 document.getElementById("rolodex").value = rolodex;
87 theForm.submit();
88}
89
90function gotoAccount(rolodex,pageIndex,account,ctx)
91{
92 if(pageIndex == null)
93 pageIndex = '0';
94 document.getElementById("pageIndex").value = pageIndex;
95 document.getElementById("rolodex").value = rolodex;
96 document.getElementById("aid").value = account;
97 document.getElementById("cid").value = ctx;
98 theForm.submit();
99}
100
101function gotoDetails(rolodex,pageIndex,ctx)
102{
103 if(pageIndex == null)
104 pageIndex = '0';
105 document.getElementById("pageIndex").value = pageIndex;
106 document.getElementById("rolodex").value = rolodex;
107 document.getElementById("cid").value = ctx;
108 theForm.submit();
109}
110
111-->
112</script>
113
114#foreach($user in $sfaUsers)
115 <script>addUser('${user.Id}','${user.Name}');</script>
116#end
117
118#if( !$Strings.IsNullOrEmpty($ctx_id ))
119
120 <script>window.location.hash='${ctx_id}';</script>
121
122#end
123
124<span class="ms-linksectionheader"><h3 class="ms-standardheader">Search</h3></span>
125<blockquote style="margin:10px">
126
127<!-- Search area -->
128<input type="hidden" name="pageIndex" value="$!{pageIndex}" />
129<input type="hidden" name="rolodex" value="$!{rolodex}" />
130<input type="hidden" name="cid" value="$!{ctx_id}" />
131
132<table cellpadding="2" cellspacing="0">
133 <tr>
134 <td>Find a lead whose
135 <select name="searchType">
136 <option value="Name" #if($searchType == "LastName")selected #end>Name</option>
137 </select>
138 contains
139 <input type="text" name="searchCriteria" value="" />
140 </td>
141 <td>
142 <a title="Find Account" href="javascript:applySearch();">
143 <img title="Go Search" alt="Find Employee" src="_layouts/images/gosearch.gif" style="border-width:0px;" />
144 </a>
145 </td>
146 </tr>
147</table>
148</blockquote>
149
150<span class="ms-linksectionheader"><h3 class="ms-standardheader">Filter by salesperson:</h3></span>
151<blockquote style="margin:10px">
152
153<!-- Rollodex -->
154<table cellpadding="2" cellspacing="2">
155 <tr>
156
157 #foreach($user in $sfaUsers)
158 <td class="ms-vb"><a href="javascript:gotoRolodex('$user.Id');">$user.Name</a>&nbsp;|</td>
159 #end
160
161 <td class="ms-vb"><a href="javascript:gotoRolodex('All');">All</a></td>
162 <tr>
163</table>
164</blockquote>
165
166## Setup Opportunity
167#set( $properties =["Id", "Name", "Title", "Description", "Email", "OwnerId", "CreatedDate", "IsUnreadByOwner", "Company", "LeadSource", "Status", "Phone"] )
168
169## Get the matching entries
170#set( $sfaLeads= $ApexLeads.GetLeads($searchFilter, $leadsOrderBy, $pageIndex, $pageSize, $properties) )
171
172## Get the result data
173#set( $firstItemNumber = $pageIndex * $pageSize + 1 )
174#set( $lastItemNumber = $firstItemNumber + $sfaLeads.Count - 1 )
175#set( $prevPageIndex = $pageIndex - 1 )
176#set( $nextPageIndex = $pageIndex + 1 )
177
178<!-- Toolbar -->
179<table class="ms-menutoolbar" cellpadding="5" cellspacing="0" border="0" width="95%" >
180 <tr>
181 <td class="ms-toolbar"></td>
182
183 <td width="99%" class="ms-toolbar" nowrap>
184 <IMG SRC="_layouts/images/blank.gif" width=1 height=18 alt=""></td>
185
186 <td class="ms-toolbar" nowrap="true">
187 <table cellpadding="0" cellspacing="0" border="0">
188 <tr>
189 #if( $pageIndex > 0 )
190 <td>
191 <img src="_layouts/images/prev.gif" border="0" alt="Previous Page" onclick="gotoPageIndex($prevPageIndex);" /></td>
192 #end
193
194 <td class="ms-listheaderlabel" nowrap>&nbsp;${firstItemNumber}-${lastItemNumber}&nbsp;</td>
195
196 #if( $sfaLeads.Count == $pageSize )
197 <td>
198 <img src="_layouts/1033/images/next.gif" border="0" alt="Next Page" onclick="gotoPageIndex($nextPageIndex);" /></td>
199 #end
200 </tr>
201 </table>
202 </td>
203
204 <td class=ms-separator>|</td>
205
206 <td class="ms-toolbar" nowrap="true">Show &nbsp;&nbsp;</td>
207 <td class="ms-toolbar" nowrap="true">
208 <select name="pageSize" onchange="setPageSize();">
209 <option value="5" #if($pageSize == 5) selected #end>5</option>
210 <option value="10"#if($pageSize == 10) selected #end>10</option>
211 <option value="15"#if($pageSize == 15) selected #end>15</option>
212 <option value="50"#if($pageSize == 50) selected #end>50</option>
213 <option value="100"#if($pageSize == 100) selected #end>100</option>
214 </select>
215 </td>
216
217 <td>&nbsp;&nbsp;&nbsp;</td>
218 </tr>
219</table>
220
221
222<!-- Results area -->
223#foreach($pidx in [5..0])
224 #beforeall
225 <table class="ms-listviewtable" cellpadding="8" cellspacing="0" width="95%" border="0">
226 <tr class="ms-viewheadertr">
227 <th class="ms-vh2-nofilter"></th>
228 <th class="ms-vh2-nofilter">Company</th>
229 <th class="ms-vh2-nofilter">Source</th>
230 <th class="ms-vh2-nofilter">Status</th>
231 <th class="ms-vh2-nofilter">Name</th>
232 <th class="ms-vh2-nofilter">Title</th>
233 <th class="ms-vh2-nofilter">Email</th>
234 <th class="ms-vh2-nofilter">Phone</th>
235 <th class="ms-vh2-nofilter">Created date</th>
236 <th class="ms-vh2-nofilter">Salesperson</th>
237 </tr>
238 #before
239 #set( $minp = $periods.get_item( $pidx ))
240 #set( $maxp = $minp )
241 #set( $periodTitle = $null )
242 #set( $npidx = $pidx + 1 )
243 #if( $pidx == 0 )
244 #set( $lpidx = $pidx + 1 )
245 #set( $lastMin = $periods.get_item( $lpidx ))
246 #set( $lastMin = $lastMin * -1 )
247 #set( $lastMax = $minOpp * -1 )
248 #set( $periodTitle = $Strings.Format( 'Created between {0} and {1} days ago', $lastMin, $lastMax ) )
249 #set( $maxp = $periods.get_item( $npidx ) )
250 #elseif ( $pidx == 6 )
251 ## no items will render on the last pass
252 #else
253 #set( $maxp = $periods.get_item( $npidx ) )
254 #set( $tmp = $minp * -1)
255 #set( $periodTitle = $Strings.Format('{0} days ago', $tmp ) )
256 #end
257 #if( $minp > $minOpp && $maxp < $maxOpp )
258 #set( $tmp = $maxp * -1)
259 #if( $tmp == 0 )
260 #set( $periodTitle = "Created within the past week" )
261 #else
262 #set( $periodTitle = $Strings.Format( 'Created between {0} and {1}', $tmp, $periodTitle ) )
263 #end
264
265 #end
266 #set( $low = $DateTimes.Today.AddDays( $minp ) )
267 #set( $high = $DateTimes.Today.AddDays( $maxp ) )
268 #set( $titleRendered = $false )
269 #set( $cnt = 0 )
270 #each
271 #foreach( $sfaLead in $sfaLeads )
272 #before
273 #set( $shouldRender = $false )
274 #if( $sfaLead.CreatedDate.CompareTo($low) > 0 && $sfaLead.CreatedDate.CompareTo($high) <= 0 )
275 #set( $shouldRender = $true)
276 #end
277 ## Normal
278 #set( $hl = "background-color:transparent;" )
279 ## Selected
280 #if($ctx_id != $null && $sfaLead.Id == $ctx_id)
281 #set( $hl = "background-color:#B0C4DE;" )
282 #end
283 ## Unread
284 #if($sfaLead.IsUnreadByOwner == $true )
285 #set( $hl = "$!{hl}color:red;" )
286 #end
287 #if($shouldRender == $true && $titleRendered == $false)
288 #set( $titleRendered = $true )
289 <tr><td colspan="10" class="ms-vb2" style="width:100%;background-color:#98AFC7"><strong>$!{periodTitle}</strong></td></tr>
290 #end
291 #odd
292 #if($shouldRender == $true)
293 <tr class="">
294 #end
295 #even
296 #if($shouldRender == $true)
297 <tr class="ms-alternating">
298 #end
299 #each
300 #if($shouldRender == $true)
301 #set( $cnt = $cnt + 1 )
302 <td class="ms-vb2" style="width:15px;text-align:center;$!{hl}">#if( $Strings.IsNullOrEmpty($sfaLead.Description) != $true )<a title="Click for notes" href="javascript:gotoDetails('$!{rolodex}','$!{pageIndex}', '$!{sfaLead.Id}')"><img alt="Click for notes" style="border:0px" src="_layouts/images/ATTACHTB.GIF"></a>#end</td>
303 <td class="ms-vb2" style="$!{hl}">$sfaLead.Company</td>
304 <td class="ms-vb2" style="$!{hl}">$sfaLead.LeadSource</td>
305 <td class="ms-vb2" style="$!{hl}">$sfaLead.Status</td>
306 <td class="ms-vb2" style="$!{hl}">$sfaLead.Name</td>
307 <td class="ms-vb2" style="$!{hl}">$sfaLead.Title</td>
308 <td class="ms-vb2" style="$!{hl}"><a href="mailto:${sfaLead.Email}">$sfaLead.Email</a></td>
309 <td class="ms-vb2" style="$!{hl}">$sfaLead.Phone</td>
310 <td class="ms-vb2" style="$!{hl}">$sfaLead.CreatedDate.ToString("d")</td>
311 <td class="ms-vb2" style="$!{hl}"><script>document.write(users['${sfaLead.OwnerId}']);</script></td>
312 #end
313 #after
314 #if($shouldRender == $true)
315
316 #if( $Strings.IsNullOrEmpty($sfaLead.Description) != $true && $ctx_id != $null && $ctx_id == $sfaLead.Id)
317 </tr>
318 <tr>
319 <td colspan=6 style="padding-left:75px">
320 <table style="background-color:#F5F5F5;border-width:1px;border-style:solid;border-color:black">
321 <tr>
322 <td style="padding:12px"><strong><u>Notes:</u></strong><br/><br/>$sfaLead.Description</td>
323 </tr>
324 </table>
325 </td>
326 #else
327 </tr>
328 #end
329 #end
330 #afterall
331 #if( $cnt > 0 )
332 <tr>
333 #if ( $cnt == 1 )
334 <td colspan="9" class="ms-vb2" style="text-align:left;font-size:smaller">$Strings.Format( '{0} lead was {1}', $!{cnt}, $periodTitle.ToLower() )</td>
335 #else
336 <td colspan="9" class="ms-vb2" style="text-align:left;font-size:smaller">$Strings.Format( '{0} leads were {1}', $!{cnt}, $periodTitle.ToLower() )</td>
337 #end
338 <td class="ms-vb2"></td>
339 <td class="ms-vb2"><br/><br/><br/></td>
340 </tr>
341 #end
342 #nodata
343 #if($shouldRender)
344 <div style="padding:10px">No Leads found in range.</div>
345 #end
346 #end
347 #afterall
348 </table>
349 #nodata
350 <div style="padding:10px">No Leads found in range.</div>
351 #end
352<div>

This snippet create a Leads Activity report from salesforce.com leads data. The SharePoint Data Zoom Web Part extension for salesforce.com is required.

Example output:

http://www.siafoo.net/image/151