<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SageCRMFun.com</title>
	<atom:link href="http://www.sagecrmfun.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sagecrmfun.com</link>
	<description>Tips. Tricks. Answers. For Sage CRM by Sage Software (unofficial)</description>
	<lastBuildDate>Tue, 14 Jul 2009 20:31:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Good, Bad, and Ugly of Table Level Scripts(CRM v6.2 SP1)</title>
		<link>http://www.sagecrmfun.com/2009/07/the-good-bad-and-ugly-of-table-level-scriptscrm-v6-2-sp1/</link>
		<comments>http://www.sagecrmfun.com/2009/07/the-good-bad-and-ugly-of-table-level-scriptscrm-v6-2-sp1/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 20:31:25 +0000</pubDate>
		<dc:creator>Matt Taylor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sagecrmfun.com/2009/07/the-good-bad-and-ugly-of-table-level-scriptscrm-v6-2-sp1/</guid>
		<description><![CDATA[&#160;
 
&#160;
Table level scripts are the perfect compliment to client side actions such as create scripts and on change script because it is server side and allows you to run code based on inserting, updating, or deleting a record.&#160; My goal was to update “Average Certainty”, “Weighted Average”, and “Total Forecast” on the ‘Company Summary’ [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2009/07/opposummarycalculations.png"><img title="opposummarycalculations" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="207" alt="opposummarycalculations" src="http://www.sagecrmfun.com/wp-content/uploads/2009/07/opposummarycalculations_thumb.png" width="946" border="0"></a> </p>
<p>&nbsp;</p>
<p>Table level scripts are the perfect compliment to client side actions such as create scripts and on change script because it is server side and allows you to run code based on inserting, updating, or deleting a record.&nbsp; My goal was to update “Average Certainty”, “Weighted Average”, and “Total Forecast” on the ‘Company Summary’ screen every time an opportunity is created, updated, or deleted.&nbsp; Once the “Show pipelines for Companies/People” is set to ‘Yes’ the Opportunity tab under company will display the pipeline and calculated fields for all opportunities.&nbsp; These calculations are done by the Dll so performing the calculations and updating the fields in real time required a table level script under opportunity.</p>
<p>&nbsp;</p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2009/07/companysummarycalculations.png"><img title="companysummarycalculations" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="201" alt="companysummarycalculations" src="http://www.sagecrmfun.com/wp-content/uploads/2009/07/companysummarycalculations_thumb.png" width="880" border="0"></a> </p>
<p>The fields above were created on the company summary screen and will hold our calculations that match the values on the opportunity tab.&nbsp; I tried using the detached table level but I faced the same problem that I have faced in the past.&nbsp; The values insert into the DelayedScriptTable, delete after the allotted time but the values on the company summary screen did not seem to update at all.&nbsp; I have also seen bugs where the entries stay in that DelayedScriptTable and never get executed.&nbsp; Sage support has informed me to stay away from Detached Table Level Scripts so I used a regular table level script here.&nbsp; </p>
<p>&nbsp;</p>
<h2>PostInsertRecord()</h2>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; height: 235px; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">function</span> PostInsertRecord()</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">ccRec = eWare.FindRecord(<span style="color: #006080">"opportunity"</span>,WhereClause);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppoid = ccRec.oppo_opportunityid;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> compid = ccRec.oppo_primarycompanyid;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppF = Values(<span style="color: #006080">'oppo_forecast'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppAC = Values(<span style="color: #006080">'oppo_certainty'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #008000">//SQL BELOW SETS THESE FIELDS WITH THE RECENT VALUE SO THE SELECT STATEMENT IS USING THE MOST RECENT AND REAL TIME DATA</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppFSQL = <span style="color: #006080">"update opportunity set oppo_forecast = '"</span>+oppF+<span style="color: #006080">"', oppo_certainty = '"</span>+oppAC+<span style="color: #006080">"' where oppo_opportunityid='"</span>+oppoid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">eWare.ExecSql(oppFSQL);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> sql = <span style="color: #006080">"SELECT TOP 20 SUM((Oppo_Forecast/Curr_Rate) * 1.000000)  AS Total_Forecast, cast(SUM(Oppo_Certainty) as numeric)/count(oppo_primarycompanyid) as Average_Certainty, (SUM((Oppo_Forecast/Curr_Rate) * 1.000000)/count(oppo_primarycompanyid))*(cast(SUM(Oppo_Certainty)as numeric)/count(oppo_primarycompanyid))/100 as Weighted_Average  FROM vListOpportunity (nolock) LEFT JOIN Currency ON Oppo_Forecast_CID = Curr_CurrencyID LEFT JOIN Custom_Captions ON Oppo_Stage = Capt_Code WHERE Oppo_PrimaryCompanyId='"</span>+compid+<span style="color: #006080">"' and ( Capt_Family = \'Oppo_Stage\' OR Capt_Family IS NULL) GROUP BY Oppo_PrimaryCompanyId ORDER BY 2 DESC"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> QueryObj = eWare.CreateQueryObj(sql);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">QueryObj.SelectSql();</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> WA = QueryObj.FieldValue(<span style="color: #006080">'Weighted_Average'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> TF = QueryObj.FieldValue(<span style="color: #006080">'Total_Forecast'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> AC = QueryObj.FieldValue(<span style="color: #006080">'Average_Certainty'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> update = <span style="color: #006080">"update company set comp_totalforecast = '"</span>+TF+<span style="color: #006080">"',  comp_weightedaverage = '"</span>+WA+<span style="color: #006080">"', comp_averagecertainty = '"</span>+AC+<span style="color: #006080">"' from company  where comp_companyid ='"</span>+compid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">eWare.ExecSql(update);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">  </pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>I use the “WhereClause” to get the opportunity record id&nbsp; just created.&nbsp; I used Values() in order to get the certainty and forecast values I just entered for that opportunity.&nbsp; I have to set the forecast and certainty values ourselves because the Dll does not do the insert command until after the post insert table level script code is run.&nbsp; Since I do a select statement that performs our calculations on all of the opportunities these forecast and certainty values need to be saved into the database before it is run.&nbsp; This is one of the “bad” things about the PostInsertRecord because it requires us to manually update the opportunity table before CRM does it by design.&nbsp; The “ugly” part about the InsertRecord is it runs code from the UpdateRecord function causing undefined for the Values() method.&nbsp; Once the code does the calculation it updates the company table by inserting those calculations into the fields displayed on the company summary page.</p>
<p>&nbsp;</p>
<h2>UpdateRecord()</h2>
<p>&nbsp;</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">function</span> UpdateRecord()</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> compid =  eWare.GetContextInfo(<span style="color: #006080">'opportunity'</span>, <span style="color: #006080">'oppo_primarycompanyid'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppoid =  eWare.GetContextInfo(<span style="color: #006080">'opportunity'</span>, <span style="color: #006080">'oppo_opportunityid'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppF = <span style="color: #0000ff">new</span> String(Values(<span style="color: #006080">'oppo_forecast'</span>));</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppAC = <span style="color: #0000ff">new</span> String(Values(<span style="color: #006080">'oppo_certainty'</span>));</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">if</span>(oppF!=<span style="color: #006080">'undefined'</span>)</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #008000">//SQL BELOW SETS THESE FIELDS WITH THE RECENT VALUE SO THE SELECT STATEMENT IS USING THE MOST RECENT AND REAL TIME DATA</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppFSQL = <span style="color: #006080">"update opportunity set oppo_forecast = '"</span>+oppF+<span style="color: #006080">"', oppo_certainty = '"</span>+oppAC+<span style="color: #006080">"' where oppo_opportunityid='"</span>+oppoid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">eWare.ExecSql(oppFSQL);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> sql = <span style="color: #006080">"SELECT TOP 20 SUM((Oppo_Forecast/Curr_Rate) * 1.000000)  AS Total_Forecast, cast(SUM(Oppo_Certainty) as numeric)/count(oppo_primarycompanyid) as Average_Certainty, (SUM((Oppo_Forecast/Curr_Rate) * 1.000000)/count(oppo_primarycompanyid))*(cast(SUM(Oppo_Certainty)as numeric)/count(oppo_primarycompanyid))/100 as Weighted_Average  FROM vListOpportunity (nolock) LEFT JOIN Currency ON Oppo_Forecast_CID = Curr_CurrencyID LEFT JOIN Custom_Captions ON Oppo_Stage = Capt_Code WHERE Oppo_PrimaryCompanyId='"</span>+compid+<span style="color: #006080">"' and ( Capt_Family = \'Oppo_Stage\' OR Capt_Family IS NULL) GROUP BY Oppo_PrimaryCompanyId ORDER BY 2 DESC"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> QueryObj = eWare.CreateQueryObj(sql);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">QueryObj.SelectSql();</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> WA = QueryObj.FieldValue(<span style="color: #006080">'Weighted_Average'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> TF = QueryObj.FieldValue(<span style="color: #006080">'Total_Forecast'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> AC = QueryObj.FieldValue(<span style="color: #006080">'Average_Certainty'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> update = <span style="color: #006080">"update company set comp_totalforecast = '"</span>+TF+<span style="color: #006080">"',  comp_weightedaverage = '"</span>+WA+<span style="color: #006080">"', comp_averagecertainty = '"</span>+AC+<span style="color: #006080">"' from company  where comp_companyid ='"</span>+compid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">eWare.ExecSql(update);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>I need to use an “If Statement” on the forecast or certainty value because of the “ugly” part of table level scripts mentioned above.&nbsp; It will only run the code below the “if statement” if it is a true update on the record.&nbsp; Essentially the same code in the InsertRecord is run in the UpdateRecord but I use GetContextInfo in order to get the opportunity and company id values.&nbsp; It would be nice if they had a post update function that ran the code after the update statement because when looking at the SQL logs I discovered that the code runs before the values get updated in the opportunity table.&nbsp; </p>
<p>&nbsp;</p>
<h2>DeleteRecord()</h2>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: 'Courier New', courier, monospace; background-color: #f4f4f4; text-align: left">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">function</span> DeleteRecord()</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">{</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #008000">//WE HAVE TO ZERO OUT THE VALUES AND MINUS FROM THE COUNT IN THE SQL STATEMENT BECAUSE IT NEEDS TO DO THE UPDATES ON THE CALCULATION BEFORE THIS RECORD GETS DELETED</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> compid =  eWare.GetContextInfo(<span style="color: #006080">'opportunity'</span>, <span style="color: #006080">'oppo_primarycompanyid'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppoid =  eWare.GetContextInfo(<span style="color: #006080">'opportunity'</span>, <span style="color: #006080">'oppo_opportunityid'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppF = 0;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppAC = 0;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #008000">//SQL BELOW SETS THESE FIELDS WITH THE RECENT VALUE SO THE SELECT STATEMENT IS USING THE MOST RECENT AND REAL TIME DATA</span></pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> oppFSQL = <span style="color: #006080">"update opportunity set oppo_forecast = '"</span>+oppF+<span style="color: #006080">"', oppo_certainty = '"</span>+oppAC+<span style="color: #006080">"' where oppo_opportunityid='"</span>+oppoid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">eWare.ExecSql(oppFSQL);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> sql = <span style="color: #006080">"SELECT TOP 20 SUM((Oppo_Forecast/Curr_Rate) * 1.000000)  AS Total_Forecast, cast(SUM(Oppo_Certainty) as numeric)/(count(oppo_primarycompanyid)-1) as Average_Certainty, (SUM((Oppo_Forecast/Curr_Rate) * 1.000000)/(count(oppo_primarycompanyid)-1))*(cast(SUM(Oppo_Certainty)as numeric)/(count(oppo_primarycompanyid)-1))/100 as Weighted_Average  FROM vListOpportunity (nolock) LEFT JOIN Currency ON Oppo_Forecast_CID = Curr_CurrencyID LEFT JOIN Custom_Captions ON Oppo_Stage = Capt_Code WHERE Oppo_PrimaryCompanyId='"</span>+compid+<span style="color: #006080">"' and ( Capt_Family = \'Oppo_Stage\' OR Capt_Family IS NULL) GROUP BY Oppo_PrimaryCompanyId ORDER BY 2 DESC"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> QueryObj = eWare.CreateQueryObj(sql);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">QueryObj.SelectSql();</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> WA = QueryObj.FieldValue(<span style="color: #006080">'Weighted_Average'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> TF = QueryObj.FieldValue(<span style="color: #006080">'Total_Forecast'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> AC = QueryObj.FieldValue(<span style="color: #006080">'Average_Certainty'</span>);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none"><span style="color: #0000ff">var</span> update = <span style="color: #006080">"update company set comp_totalforecast = '"</span>+TF+<span style="color: #006080">"',  comp_weightedaverage = '"</span>+WA+<span style="color: #006080">"', comp_averagecertainty = '"</span>+AC+<span style="color: #006080">"' from company  where comp_companyid ='"</span>+compid+<span style="color: #006080">"'"</span>;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">eWare.ExecSql(update);</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">&nbsp;</pre>
<p><!--CRLF-->
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">}</pre>
<p><!--CRLF--></div>
</div>
<p>&nbsp;</p>
<p>The code varies the most in the DeleteRecord function because the code runs before the record is deleted so the calculation that is running and updating the fields on the company summary screen are using the same values that I had before.&nbsp; I need the calculations to take place after the record is gone so I can get accurate numbers.&nbsp; Unfortunately, there isn’t a post delete function either so I had to 0 out the forecast and certainty values and then do the calculations based on the total number of opportunities minus 1 accounting for this record I am about to delete.&nbsp; Then I do the update command and the record gets deleted.</p>
<p>&nbsp;</p>
<p>In conclusion, the table level script feature is “good” for running JSCRIPT/SQL commands to update data when you are on a different entities but the detached table level script has been proven to be “ugly” and the functionality in the table level script can be “bad”.&nbsp; These are the work arounds I had to use but I am hopeful that Sage will improve the table level script feature in upcoming versions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sagecrmfun.com/2009/07/the-good-bad-and-ugly-of-table-level-scriptscrm-v6-2-sp1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sage CRM &#8211; Fiddler2</title>
		<link>http://www.sagecrmfun.com/2009/06/sage-crm-fiddler2/</link>
		<comments>http://www.sagecrmfun.com/2009/06/sage-crm-fiddler2/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 17:39:35 +0000</pubDate>
		<dc:creator>Ryan Lowdermilk</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Network]]></category>

		<guid isPermaLink="false">http://www.sagecrmfun.com/?p=32</guid>
		<description><![CDATA[Our development team utilizes several tools to accelerate and enhance the development of customizations. Whether we use Firebug for Firefox to troubleshoot JavaScript errors/oddities or PSPad to quickly mockup code, each tool fills a nitch, and is essential to delivering solid customizations. One tool we use for “super fancy” customizations involving asynchronous callbacks is Fiddler2.
What [...]]]></description>
			<content:encoded><![CDATA[<p>Our development team utilizes several tools to accelerate and enhance the development of customizations. Whether we use <a href="http://bit.ly/E583n">Firebug</a> for Firefox to troubleshoot JavaScript errors/oddities or <a href="http://bit.ly/U92nr">PSPad</a> to quickly mockup code, each tool fills a nitch, and is essential to delivering solid customizations. One tool we use for “super fancy” customizations involving asynchronous callbacks is <a href="http://bit.ly/hCHhD">Fiddler2</a>.</p>
<h3>What is Fiddler2?</h3>
<p>Fiddler2 is a web debugging proxy. Simply, Fiddler2 allows web based traffic (HTTP and HTTPS) to be monitored, debugged, replayed, and mangled for your pleasure! </p>
<blockquote><p>Fiddler is a Web Debugging Proxy which logs all HTTP(S) traffic between your computer and the Internet. Fiddler allows you to inspect all HTTP(S) traffic, set breakpoints, and &#8220;fiddle&#8221; with incoming or outgoing data. Fiddler includes a powerful event-based scripting subsystem, and can be extended using any .NET language.</p>
<p>Fiddler is freeware and can debug traffic from virtually any application, including Internet Explorer, Mozilla Firefox, Opera, and thousands more.</p></blockquote>
<p>In addition to the core features, Fiddler2, also has a 3rd party plug-in model, allowing users to extend the functionality of Fiddler2. All for FREE!</p>
<p> </p>
<h3>Why would I use Fiddler2?</h3>
<p>A valid question. There are several tasks we perform with Fiddler2; here are a couple:</p>
<ul>
<li><strong>Find Hidden and Unhidden Form Values – </strong>Form values can be hard to find. Clicking on the “WebForms” tab reveals hidden and unhidden Form values.</li>
<li><strong>Troubleshooting Asynchronous Calls</strong> – Asynchronous calls can’t be seen from the web browser. However, using Fiddler2, we are able to see the actual call to the backend page. We do this to a.) Ensure the call is being made and b.) Validate that the correct QueryString parameters are being appended.</li>
<li><strong>Accelerate Development – </strong>When testing, the time spent clicking through 2-3 screens, to reach a button or hyperlink you want to test can, can add up. The “Replay” feature in Fiddler2 speeds this process up. Allowing you to resend a previous request and view the results right inside of Fiddler2!</li>
</ul>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2009/06/20090623-102812.jpg"><img style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" title="Screenshot of Fiddler2" src="http://www.sagecrmfun.com/wp-content/uploads/2009/06/20090623-102812-thumb.jpg" border="0" alt="Screenshot of Fiddler2" width="850" height="520" /></a></p>
<h3>Use the right tool?</h3>
<p>As with anything, using the right tool is essential. Although Fiddler2 may not be for everyone, we love it. In fact, in a post to come, we hope to show you how we used it to “work around” a bug in SageCRM.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sagecrmfun.com/2009/06/sage-crm-fiddler2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sage CRM &#8211; Line Item Mail Merge Document for a custom entity using ASP/HTML/SQL</title>
		<link>http://www.sagecrmfun.com/2009/03/sage-crm-line-item-mail-merge-document-for-a-custom-entity-using-asphtmlsql/</link>
		<comments>http://www.sagecrmfun.com/2009/03/sage-crm-line-item-mail-merge-document-for-a-custom-entity-using-asphtmlsql/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 22:08:17 +0000</pubDate>
		<dc:creator>Matt Taylor</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.sagecrmfun.com/2009/03/sage-crm-line-item-mail-merge-document-for-a-custom-entity-using-asphtmlsql/</guid>
		<description><![CDATA[&#160;
CRM has the ability to carry out a mail merge document for the following entities.

Company 
Person 
Opportunity 
Quotes 
Orders 
Case 
Lead 
Custom Entities 

&#160;
Additionally, CRM comes with a template that can be used with “Quotes” and “Orders” to fill multiple line items into the merge document &#8211; but there are limitations.
&#160;
What if your custom entity [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>CRM has the ability to carry out a mail merge document for the following entities.</p>
<ul>
<li>Company </li>
<li>Person </li>
<li>Opportunity </li>
<li>Quotes </li>
<li>Orders </li>
<li>Case </li>
<li>Lead </li>
<li>Custom Entities </li>
</ul>
<p>&#160;</p>
<p>Additionally, CRM comes with a template that can be used with “Quotes” and “Orders” to fill multiple line items into the merge document &#8211; but there are limitations.</p>
<p>&#160;</p>
<h3>What if your custom entity has multiple records that need to merge into line items?</h3>
<p>&#160;</p>
<p>In this example we have a custom entity called &quot;Parts Used&quot;.&#160;&#160; This entity appears underneath a tab, under Cases, called “Parts Used”.&#160; Upon clicking the Tab a list of parts are displayed for the given Case.&#160; Unfortunately we are unable to tweak the PanoplySalesQuote.doc to support multiple line items for our custom entity due to the design capabilities of CRM.&#160; Although, we can create a merge document for the custom entity by tweaking the vMailMergeCase view to support our custom entity fields we will be unable to produce a document that merges multiple line items.</p>
<p>&#160;</p>
<h3>The ASP page that handles the SQL and HTML</h3>
<p>&#160;</p>
<p>The solution is an ASP page which can be printed just like a Word document.&#160; The ASP page will perform a SQL statement that will display each record on a new line in our HTML form.&#160; For example, if there are five parts used then it will write the five records on different lines in the HTML form.&#160; If there is only one part used it will only write one line on the html form.&#160; New lines are created based on the number of records.&#160; We use a while loop to populate a new line for each record if it exists. </p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">var</span>  caseid = eWare.GetContextInfo(<span style="color: #006080">&quot;Cases&quot;</span>, <span style="color: #006080">&quot;case_caseid&quot;</span>);

<span style="color: #0000ff">var</span> qryobj = eWare.CreateQueryObj(<span style="color: #006080">&quot;SELECT * from caseproducts inner join newproduct on cp_productid = prod_productid where cp_deleted is null and cp_caseid=&quot;</span>+caseid);
qryobj.SelectSQL();

<span style="color: #0000ff">while</span>(!qryobj.eof)
{
Response.Write(<span style="color: #006080">&quot;&lt;tr&gt;&quot;</span>);
Response.Write(<span style="color: #006080">&quot;&lt;td class='style20'&gt;&quot;</span>+ qryobj.FieldValue(<span style="color: #006080">&quot;cp_qtyint&quot;</span>)+<span style="color: #006080">&quot;&lt;/td&gt;&quot;</span>);
Response.Write(<span style="color: #006080">&quot;&lt;td class='style22'&gt;&quot;</span>+qryobj.FieldValue(<span style="color: #006080">&quot;prod_code&quot;</span>)+<span style="color: #006080">&quot;&lt;/td&gt;&quot;</span>);
Response.Write(<span style="color: #006080">&quot;&lt;td class='style18'&gt;&quot;</span>+qryobj.FieldValue(<span style="color: #006080">&quot;prod_name&quot;</span>)+<span style="color: #006080">&quot;&lt;/td&gt;&quot;</span>);
Response.Write(<span style="color: #006080">&quot;&lt;td class='style25'&gt; &quot;</span>+qryobj.FieldValue(<span style="color: #006080">&quot;cp_status&quot;</span>)+<span style="color: #006080">&quot;&lt;/td&gt;&quot;</span>);

Response.Write(<span style="color: #006080">&quot;&lt;/tr&gt;&quot;</span>);
 qryobj.NextRecord();
}</pre>
</div>
<p>&#160;</p>
<p>&#160;</p>
<h3>The line items that merge into the document</h3>
<p>&#160;</p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2009/03/image.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="186" alt="image" src="http://www.sagecrmfun.com/wp-content/uploads/2009/03/image-thumb.png" width="835" border="0" /></a> </p>
<p>There were two items entered so when service form is selected both parts used on this case will populate in “Parts Used In This Service”.&#160; </p>
<p>&#160;</p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2009/03/image1.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="545" alt="image" src="http://www.sagecrmfun.com/wp-content/uploads/2009/03/image-thumb1.png" width="832" border="0" /></a> </p>
<p>&#160;</p>
<p>The sql code will run every time the form is accessed so if another part is added it will show up on the form.</p>
<p>&#160;</p>
<h3>Drawbacks</h3>
<p>&#160;</p>
<p>Although you are able to display this merged document on a tab and print it, this customization would not allow you to save it into a word document like the built in CRM functionality.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sagecrmfun.com/2009/03/sage-crm-line-item-mail-merge-document-for-a-custom-entity-using-asphtmlsql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sage CRM &#8211; Making your SQL pretty (human readable)</title>
		<link>http://www.sagecrmfun.com/2009/01/sagecrm-making-your-sql-pretty-human-readable/</link>
		<comments>http://www.sagecrmfun.com/2009/01/sagecrm-making-your-sql-pretty-human-readable/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 23:54:14 +0000</pubDate>
		<dc:creator>Ryan Lowdermilk</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[formatting]]></category>

		<guid isPermaLink="false">http://www.sagecrmfun.com/?p=31</guid>
		<description><![CDATA[We love SQL. We love reading it, writing it, proofing it, improving it and sometimes dropping it (always sad). We also like to see our SQL dressed to impress- not looking flabby but lean and mean. One tool we use to buff and shine our SQL is &#34;Instant SQL Formatter&#34; (ISF). ISF, a web site [...]]]></description>
			<content:encoded><![CDATA[<p>We love SQL. We love reading it, writing it, proofing it, improving it and sometimes dropping it (always sad). We also like to see our SQL dressed to impress- not looking flabby but lean and mean. One tool we use to buff and shine our SQL is &quot;<a href="http://www.wangz.net/pp/sqlformat.htm" target="_blank">Instant SQL Formatter</a>&quot; (ISF). ISF, a web site created by Gudu Software, takes ugly SQL and makes it pretty. Why is this important? Frankly, it makes debugging and modifying existing SQL statements easier &#8211; and we like easy. Let&#8217;s see an example.</p>
<h3>&quot;It&#8217;s not that it&#8217;s ugly&#8230; it&#8217;s just not pretty&quot;</h3>
<p>Below we have &quot;vSearchListCompany&quot;. This is a popular SQL view &#8211; used in a variety of Sage CRM functions. Consequently, this would be the same view that seemly breaks when applying patches &#8211; forcing one to limit the amount of fields returned in order to fix the error. But we can save that post for another day &#8211; back to &quot;vSearchListCompany&quot;. As we see (screen shot) not all SQL statements are easy on the eyes. Attempting to add a column, modify the first name and last name concatenation, or removing a column can get messy. To make this a little easier, let&#8217;s use ISF.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="334" alt="vSearchListCompany in all it&#39;s glory!" src="http://www.sagecrmfun.com/wp-content/uploads/2009/01/image.png" width="1036" border="0" /></p>
<h3>&quot;We are going to PUMP&#8230;. You Up!&quot;</h3>
<p>Now, at first visit, ISF can seem a little disorganized &#8211; offering a plethora of options. <em>Side note: We use ISF&#8217;s impressive array of options for more than beautifying SQL. ISF can be a huge time saver for creating JScript or C# string variables based on your SQL statements -&#160; I implore you to explore the settings</em>. For this example, we are only concerned with two settings: Database and Output. These two settings inform ISF what database platform the SQL statement is coming from and what format to output the results. For this example, our database format is &quot;SQL&quot; and our output format is &quot;SQL (Text)&quot;. Selecting &quot;SQL (Text)&quot; as the output format will deliver a SQL statement &#8211; executable in SQL Query Analyzer. After selecting the appropriate settings, take your SQL statement, copy and paste it into the provided text box and click &quot;Format SQL&quot;.</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="450" alt="Install SQL Formatter" src="http://www.sagecrmfun.com/wp-content/uploads/2009/01/image1.png" width="1017" border="0" /></p>
<h3>&quot;Looking SWEEEEET!&quot;</h3>
<p>After a few milliseconds, our new and improved SQL is unveiled. We can see (below) the resulting SQL is much easier to work with. Adding or modifying existing columns becomes a cinch. Additionally, the SELECTION fields along with the JOIN and WHERE clauses are easier to disseminate. From here, we typically copy the resulting SQL statement into SQL Query Analyzer and work with it from there. Also, it is not uncommon for us to keep the formatting provided by ISF when pasting BACK into Sage CRM. This way, if we need to make changes in the future, we are ready to go!</p>
<div>
<pre class="csharpcode">/* Powered <span class="kwrd">by</span> <span class="kwrd">General</span> <span class="kwrd">SQL</span> Parser (www.sqlparser.com) */

<span class="kwrd">CREATE</span> <span class="kwrd">VIEW</span> VSEARCHLISTCOMPANY
<span class="kwrd">AS</span>
  <span class="kwrd">SELECT</span> RTRIM(ISNULL(PERS_FIRSTNAME,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(PERS_LASTNAME,<span class="str">''</span>))                                                           <span class="kwrd">AS</span> PERS_FULLNAME,
         RTRIM(ISNULL(PERS_PHONECOUNTRYCODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(PERS_PHONEAREACODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(PERS_PHONENUMBER,<span class="str">''</span>))    <span class="kwrd">AS</span> PERS_PHONEFULLNUMBER,
         RTRIM(ISNULL(PERS_FAXCOUNTRYCODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(PERS_FAXAREACODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(PERS_FAXNUMBER,<span class="str">''</span>))          <span class="kwrd">AS</span> PERS_FAXFULLNUMBER,
         RTRIM(ISNULL(COMP_PHONECOUNTRYCODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(COMP_PHONEAREACODE,<span class="str">''</span>)) + <span class="str">' '</span> + RTRIM(ISNULL(COMP_PHONENUMBER,<span class="str">''</span>))    <span class="kwrd">AS</span> COMP_PHONEFULLNUMBER,
         COMPANY.*,
         PERSON.*,
         ADDRESS.*
  <span class="kwrd">FROM</span>   COMPANY
         <span class="kwrd">LEFT</span> <span class="kwrd">JOIN</span> PERSON
           <span class="kwrd">ON</span> COMP_PRIMARYPERSONID = PERS_PERSONID
         <span class="kwrd">LEFT</span> <span class="kwrd">JOIN</span> ADDRESS
           <span class="kwrd">ON</span> COMP_PRIMARYADDRESSID = ADDR_ADDRESSID
  <span class="kwrd">WHERE</span>  COMP_DELETED <span class="kwrd">IS</span> <span class="kwrd">NULL</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sagecrmfun.com/2009/01/sagecrm-making-your-sql-pretty-human-readable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sage CRM &#8211; Tab is not selected when navigating multiple Custom ASP pages</title>
		<link>http://www.sagecrmfun.com/2008/05/tab-is-not-selected-when-jumping-to-other-asp-pages/</link>
		<comments>http://www.sagecrmfun.com/2008/05/tab-is-not-selected-when-jumping-to-other-asp-pages/#comments</comments>
		<pubDate>Tue, 20 May 2008 21:36:33 +0000</pubDate>
		<dc:creator>Matt Taylor</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[custom ASP]]></category>
		<category><![CDATA[Tabs]]></category>

		<guid isPermaLink="false">http://www.sagecrmfun.com/?p=19</guid>
		<description><![CDATA[&#160;
The tab for a custom ASP page will not stay highlighted when you jump to another asp page within. For Example: The screen shot below shows a custom asp page called &#34;Logins&#34;. The tab is selected within that custom asp page but when you hit new it calls another asp page.


You will notice that the [...]]]></description>
			<content:encoded><![CDATA[<div>&#160;</div>
<p>The tab for a custom ASP page will not stay highlighted when you jump to another asp page within. For Example: The screen shot below shows a custom asp page called &quot;Logins&quot;. The tab is selected within that custom asp page but when you hit new it calls another asp page.</p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2008/05/loginstabselected.gif"><img height="120" alt="Loginstabselected" src="http://www.sagecrmfun.com/wp-content/uploads/2008/05/loginstabselected-thumb.gif" width="481" /></a></p>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2008/05/loginstabnotselected.gif"><img height="118" alt="loginstabnotselected" src="http://www.sagecrmfun.com/wp-content/uploads/2008/05/loginstabnotselected-thumb.gif" width="413" /></a></p>
<p>You will notice that the tab is not selected when the other asp page is called within the first asp page by pressing the new button.</p>
<p>There are a few ways to handle this problem.</p>
<ol>
<li>You can just create a tab group and just call it within get page so it goes to it&#8217;s own tab group like Marketing.
<div>
<pre class="csharpcode">Response.Write(eWare.GetPage(<span class="str">&quot;YourTabGroup&quot;</span>);</pre>
<p><a href="http://www.sagecrmfun.com/wp-content/uploads/2008/05/tabgroup.gif"><img height="133" alt="tabgroup" src="http://www.sagecrmfun.com/wp-content/uploads/2008/05/tabgroup-thumb.gif" width="286" /></a></p>
</p></div>
</li>
<li>You can handle multiple views within 1 asp page so the tab is selected amongst the other tabs. The code below is an example of using if statements to handle different views and actions.
<div>
<pre class="csharpcode">&lt;!-- #Include file = <span class="str">&quot;accpaccrm.js&quot;</span> --&gt;
&lt;%
<span class="kwrd">if</span>(Request.QueryString(<span class="str">&quot;mode&quot;</span>) == <span class="rem">'new')</span>
{
    varCancelButton = eWare.Button(<span class="str">&quot;Cancel&quot;</span>,<span class="str">&quot;cancel.gif&quot;</span>,eWare.Url(<span class="str">&quot;login.asp&quot;</span>));
    <span class="kwrd">if</span>(eWare.Mode == View)
    {
        eWare.Mode = Edit;
    }
    varLoginNew=eWare.GetBlock(<span class="str">&quot;LoginEntry&quot;</span>);
    varThisCompany = eWare.GetContextInfo(<span class="str">&quot;Company&quot;</span>,<span class="str">&quot;comp_companyid&quot;</span>);
    LoginNew.Title = eWare.GetTrans(<span class="str">&quot;tabnames&quot;</span>,<span class="str">&quot;logins&quot;</span>);
    LoginNew.AddButton(CancelButton);
    varmyRecord = eWare.CreateRecord(<span class="str">&quot;logins&quot;</span>);
    myRecord.log_companyid=ThisCompany;
    eWare.AddContent(LoginNew.Execute(myRecord));
    <span class="kwrd">if</span>(eWare.Mode == Save)
    {
        Response.Redirect(eWare.URL(<span class="str">&quot;login.asp&quot;</span>));
    }
}
<span class="kwrd">else</span> <span class="kwrd">if</span>(parseInt(Request.QueryString(<span class="str">&quot;log_loginid&quot;</span>)) &gt; 0)
{
    varCancelButton = eWare.Button(<span class="str">&quot;Cancel&quot;</span>,<span class="str">&quot;cancel.gif&quot;</span>,eWare.Url(<span class="str">&quot;login.asp&quot;</span>));
    LoginNew=eWare.GetBlock(<span class="str">&quot;LoginEntry&quot;</span>);
    LoginNew.AddButton(CancelButton);
    LoginNew.Title = eWare.GetTrans(<span class="str">&quot;tabnames&quot;</span>,<span class="str">&quot;logins&quot;</span>);
    LoginNew.DisplayButton(Button_Default) = <span class="kwrd">true</span>;
    LoginNew.DisplayButton(Button_Delete) = <span class="kwrd">true</span>;
    varintRecordId = eWare.GetContextInfo(<span class="str">&quot;company&quot;</span>,<span class="str">&quot;comp_companyid&quot;</span>);
    ThisLoginId=Request.QueryString(<span class="str">&quot;log_loginid&quot;</span>);
    varmyRecord = eWare.FindRecord(<span class="str">&quot;logins&quot;</span>,<span class="str">&quot;log_loginid=&quot;</span>+ThisLoginId);
    eWare.AddContent(LoginNew.Execute(myRecord));
    <span class="kwrd">if</span>(eWare.Mode == PostDelete)
    {
        Response.Redirect(eWare.URL(<span class="str">&quot;login.asp&quot;</span>))
    }
    <span class="kwrd">if</span>(eWare.Mode == Save)
    {
        Response.Redirect(eWare.URL(<span class="str">&quot;login.asp&quot;</span>)+<span class="str">&quot;&amp;log_loginid=&quot;</span>+myRecord.intRecordId);
    }
}
<span class="kwrd">else</span>
{
    varThisCompany = eWare.GetContextInfo(<span class="str">&quot;Company&quot;</span>,<span class="str">&quot;comp_companyid&quot;</span>);
    varurl = eWare.Url(<span class="str">&quot;login.asp&quot;</span>)+ <span class="str">&quot;&amp;mode=new&quot;</span>;
    varnewButton = eWare.Button(<span class="str">&quot;New&quot;</span>,<span class="str">&quot;new.gif&quot;</span>, url);
    varLogins = eWare.GetBlock(<span class="str">&quot;LoginList&quot;</span>);
    Logins.AddButton(newButton);
    varArg = <span class="str">&quot;log_companyid=&quot;</span>+ThisCompany;
    eWare.AddContent(Logins.Execute(Arg));
}
Response.Write(eWare.GetPage());
%&gt;</pre>
</p></div>
</li>
</ol>
<div>&#160;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.sagecrmfun.com/2008/05/tab-is-not-selected-when-jumping-to-other-asp-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
