2022.2

Table Of Contents
Using values from the record in a script
Toaccesstherecordthatisbeingmergedtothetemplatewhenthescriptruns,usetheobjectrecord
(see"record"onpage744).
Supposeyouwanttodisplaynegativeamountsinredandpositiveamountsingreen.Assumingthat
thereisanAMOUNTfieldinyourcustomerdata,youcouldwritethefollowingscript(withtheselector:
td.amount,thatis:tablecellswiththeclass'amount').
var amount = record.fields.AMOUNT;
if (amount >= 0)
{results.css('color', 'green');}
else if (amount < 0) {
results.css('color', 'red');
}
Whenthisscriptexecutes,itstoresthevalueoftheAMOUNTfieldfromthecurrentrecordinavariable
andevaluatesit.Ifthevalueiszeroorhigher,thecoloroftextintheresults -thetablecellsinthiscase
-willbesettogreen;ifthevalueisbelowzero,thetextcolorwillbesettored.
Tip: Formoreexamplesofusingconditions,seethishow-to:Combiningrecord-based
conditions.
Ifanexpandedscriptcontainserrorsoriftherearewarnings,iconsappearintheoverviewruleronthe
righthandsideoftheeditingarea.Theseiconsareshownrelativetotheirpositioninthescriptanddo
notmoveasyouscrolldown.Youcanclickonanicontoquicklyjumptotheerrororwarning.Script
errorsarehighlightedbyaredicon,andwarningsinyellow.Thetopmosticonwilldisplayredifany
errorsexistinthescriptatall.
DesignerAPI
FeatureslikeresultsandrecorddonotexistinthenativeJavaScriptlibrary.Theseareadditional
JavaScriptfeatures,designedforuseinConnectscriptsonly.Allfeaturesdesignedforuseinthe
DesignerarelistedintheDesigner'sAPI,withalotofexamples;see"StandardScriptAPI"on
page715.
Setting the scope of a script
Theselectorofascriptcanmatchmultipleelements.Bysettingthescopeofthescriptyoucandeterm-
inewhetheryouwanttorunthescriptonce,oronce for each elementthatmatchestheselector.The
secondoptionisespeciallyusefulwhenascripttargetsrowsorcellsinaDynamicTable(see"Using
scriptsinDynamicTables"onpage395).
Tosetthescopeofascript,clickonOptionsatthebottomoftheScriptEditorwindow.Theoptionsare:
Page 373