2022.2

Table Of Contents
existingscriptintheScriptspaneonthebottomleft.
IfthescriptwasmadewithaScriptWizard,youhavetoclicktheExpandbuttonbeforeyoucan
startwritingcode.ThiswillchangetheScriptWizardintoaneditor window.
Caution: Whenyouchangeanexpandedtextscriptandsaveit,itbecomesimpossibleto
editthescriptusingtheScriptWizardagain.
2. Writethescript.ClickApplyfromtimetotimetoseeifthescriptworksasexpected.Thiswillbe
visibleonthePreviewtabinthemainworkspace.
Syntax rules
EveryscriptintheDesignermustfollowJavaScriptsyntaxrules.Forexample,eachstatementshould
endwith;andthekeywordsthatcanbeused,suchasvar todeclareavariable,areJavaScript
keywords.TherearecountlesstutorialsavailableontheInternettofamiliarizeyourselfwiththe
JavaScriptsyntax.
Forasimplescriptallthatyouneedtoknowcanbefoundonthefollowingwebpages:
https://www.w3schools.com/js/js_syntax.aspandhttps://www.w3schools.com/js/js_if_else.asp.
AfewexamplescanbefoundinaHow-to:Combiningrecordbasedconditions.
Tip: Intheeditorwindow,pressCtrl+Spacetoseetheavailablefeaturesandtheirdescriptions.
UsethearrowkeystoselectafunctionorobjectandpressEntertoinsertitinthescript.
TypeadotafterthenameofthefunctionorobjectandpressCtrl+spaceagaintoseewhichfea-
turesaresubsequentlyavailable.
Formorekeyboardshortcuts,see"Keyboardshortcuts"onpage502.
Twobasiccodeexamples
Writingascriptgenerallycomesdowntomodifyingthepiece(s)ofcontentcollectedfromthetemplate
withthescript'sselector,usingvalues,ordependingonvaluesoftherecordthatisbeingmergedtothe
templateatthemomentthescriptruns.
Modifying the template
Toaccessandchangetheresultsofthequerythatiscarriedoutwiththeselector(inotherwords:to
modifytheoutput),usetheobjectresults.
Thefollowingscript(withtheselectorp)changesthetextcolorofallparagraphstoredwithasingleline
ofcode:
results.css('color', 'red')
Itdoesthisforeachandeverycustomer,becauseitdoesnotdependonavaluefromtherecordthatis
beingmergedtothetemplate.
Page 372