Professional Documents
Culture Documents
18
7
ss
oc
ia
te
ID
C3: Protected
Credential
Information:
Version and
Date:
JS_in_PRPC/PPT/0111/1.0
ss
oc
ia
te
ID
:4
0
18
7
Created /
Reviewed By:
Confidential
ss
oc
ia
te
ID
:4
0
18
7
such way so that in most of the places PRPC out of the box feature can
be used instead of JavaScript
There are certain areas where PegaRULES Process Commander
implementation cannot be possible without using JavaScript. The best
possible ways to use JavaScript in PRPC will be discussed in this Course
Confidential
ss
oc
ia
te
ID
:4
0
18
7
Confidential
Course Structure
18
7
ss
oc
ia
te
ID
:4
0
Confidential
18
7
:4
0
ss
oc
ia
te
ID
would be viewed
Do not require access to Web server
Interactivity
Scripted -not compiled
Powerful
Object-based
Cross-Platform
Client and Server
Confidential
following reasons :
A script that is executed by the browser on a users computer
18
7
Instead of the entire page, part of the page is sent to the browser when
:4
0
ss
oc
ia
te
ID
Confidential
Java
18
7
ss
oc
ia
te
ID
:4
0
Confidential
:4
0
<input type=button
18
7
<script>Code</script>
ss
oc
ia
te
ID
onclick=JavaScript:alert(Hi); />
External references
<script src=JSFileName></script>
Confidential
Comments in JavaScript
Different comments in JavaScript are shown as follows:
// is single line comments
ss
oc
ia
te
ID
:4
0
18
7
Confidential
10
Programming Rules
JavaScript is case-sensitive
Ending statements with a semicolon is optional
Open and Close braces for scoping the embedded Java Script
ss
oc
ia
te
ID
:4
0
18
7
code is mandatory
You can apply more than one script in a same HTML file
Confidential
11
18
7
Regular Expressions
Statements
ss
oc
ia
te
ID
:4
0
Functions
Confidential
12
:4
0
18
7
ss
oc
ia
te
ID
Confidential
13
:4
0
18
7
underscore ("_")
Subsequent characters can also be digits (0-9)
As because JavaScript is case sensitive, letters include the
characters "A" through "Z" (uppercase) and the characters "a"
through "z" (lowercase)
Variables Scope:
ss
oc
ia
te
ID
Confidential
14
Object Literals:
18
7
String Literals:
:4
0
ss
oc
ia
te
ID
quotation marks
The following are examples of string literals:
"blah"
'blah'
"1234
"one line \n another line
2007, Cognizant Technology Solutions
Confidential
15
Programming JavaScript
Variables:
Howdy, numberRight, score, Ralph
Data types:
18
7
Operators:
:4
0
Control statements:
ss
oc
ia
te
ID
Keywords:
Confidential
16
18
7
function functionName(var1,var2..)
{
some code
return <Data> //optional
}
ss
oc
ia
te
ID
:4
0
Confidential
17
ss
oc
ia
te
ID
:4
0
18
7
if..else Syntax
if (condition){
code to be executed if condition is true
}
else
{
code to be executed if condition is not true
}
If.. Else ifElse Syntax
if (condition1) { code to be executed
}
else if (condition2) { code to be executed
}
else { code to be executed
}
Confidential
18
ss
oc
ia
te
ID
:4
0
18
7
switch(n) {
case 1: execute code block 1break ;
case 2: execute code block 2break ;
default: code to be executed if n is different from case 1 and 2
}
Confidential
19
Control Statements
The for loop is applied when the user know in advance, how
ss
oc
ia
te
ID
:4
0
18
7
var initval;
for(initval=startvalue;initval<=endalue;initval=initval+incrval)
{
code to be executed
}
Confidential
20
ss
oc
ia
te
ID
18
7
:4
0
while (initval<=endvalue)
{
code to be executed
}
Do..While Syntax:
do {
code to be executed
} while (var<=endvalue)
While Syntax:
Confidential
21
18
7
For..In Syntax:
ss
oc
ia
te
ID
:4
0
Confidential
22
:4
0
18
7
of Inheritance. Out of these the first and the more popular way of
working with inheritance is known as the prototype way
The prototype way or prototyping a class, usually deals with using a
function prototype instead of a class
ss
oc
ia
te
ID
For instance
function Iam () {
this.alive = true;
}
Iam.prototype.notdead = function () {
return true;
};
Confidential
23
18
7
:4
0
Now, if associates create an instance of Dave object, and call its member
methods, the result would be:
ss
oc
ia
te
ID
If any one wants to call a super method for an object, this is how it
would be called
Dave.prototype.getsBored = function ( ) {
Iam.prototype.getsBored.call(this);
return Never1;
2007, Cognizant Technology Solutions
Confidential
24
ss
oc
ia
te
ID
:4
0
18
7
Confidential
25
Cross-site scripting
Cross-site scripting (XSS):
XSS is a type of computer security vulnerability typically found in web
applications which allow code injection by malicious web users into the
web pages viewed by other users
XSS surpassed buffer overflows to become the most common publicly
reported security vulnerability in recent years, and at least 68% of
websites are likely open to XSS attacks on their users. Cross-site
scripting holes in general can be seen as vulnerabilities which allow
attackers to bypass security mechanisms. By finding clever ways of
injecting malicious scripts into web pages an attacker can gain elevated
access privileges to sensitive page content, session cookies, and a
variety of other objects
Three distinct types of XSS vulnerabilities exist: non-persistent,
persistent, and DOM-based
ss
oc
ia
te
ID
:4
0
18
7
Confidential
26
performance engineer )
Developers should reduce the amount of JavaScript on their `sites if they
18
7
:4
0
ss
oc
ia
te
ID
Confidential
27
ss
oc
ia
te
ID
:4
0
18
7
Confidential
28
18
7
affecting performance
Here are three strategies for avoiding, or at least mitigating,
the blocking behavior of inline scripts
move inline scripts to the bottom of the page - Although this still
ss
oc
ia
te
ID
:4
0
Confidential
29
18
7
ss
oc
ia
te
ID
:4
0
nonExistentFunction();
3. } catch (error) {
4.
document.write("An error has occured.")
5. }
2.
Confidential
30
Session Break
ss
oc
ia
te
ID
:4
0
18
7
Confidential
31
Q&A
ss
oc
ia
te
ID
:4
0
18
7
Confidential
32
ss
oc
ia
te
ID
:4
0
18
7
Script?
3. Is Java Script case sensitive?
Confidential
33
ss
oc
ia
te
ID
:4
0
18
7
After the Part 1 it is well understood that associates have to reduce use of
JavaScript while developing an application. There are PRPC out of the box
feature, that can be used instead of JavaScript. Those are described with
example in following slides.
Confidential
34
property
ss
oc
ia
te
ID
:4
0
18
7
Use the Edit Validate form to define a Java routine that tests the validity of
an input value in an activity that processes user input. The activity calls the
Property-Validate method, which applies the test defined in an Edit
Validate rule.
Confidential
35
18
7
Auto Complete
ss
oc
ia
te
ID
:4
0
Use an AutoComplete control to allow the user to select a value from a possibly
large set of searched text values, based on a partial string match. The system
dynamically assembles and displays a list of candidate matching values after the
user types one or a few characters of input.
For example, when searching for an employee by first name, the user can type two
characters such as "AL". An autoComplete control can run an activity to create a list
of employees in a Page List structure, one page per employee, and match on the
embedded FirstName field, presenting matching candidates Alan, Allan, Albert, and
so on.
Confidential
36
18
7
Onclick of the record in the list view, a more detailed section is visible to
the user. This detailed screen opens either in a new window or in the same
frame
ss
oc
ia
te
ID
Dynamic Select
:4
0
Any section can be included in Smart Info control which should be visible
to the user as tooltip at runtime
Dynamic select is used where the values in the dropdown are not static and
are dynamically generated. Here the values are generated either through a
list view or through an activity
Confidential
37
ss
oc
ia
te
ID
:4
0
18
7
Confidential
38
AJAX (Contd.)
PRPC OOTB Example are:
handleClientEvent(SERVER, ActivityName, &ParameterList, -1, event);
:4
0
18
7
ss
oc
ia
te
ID
ParameterList);
Confidential
39
Session Break
ss
oc
ia
te
ID
:4
0
18
7
Confidential
40
Q&A
ss
oc
ia
te
ID
:4
0
18
7
Confidential
41
ss
oc
ia
te
ID
:4
0
18
7
applications
2. What is Dynamic Select?
3. What is Auto Complete?
Confidential
42
validation
:4
0
18
7
ss
oc
ia
te
ID
Confidential
43
Confirm (<Text>);
18
7
Alert (<Text>);
:4
0
ss
oc
ia
te
ID
Confidential
44
18
7
If associate want to fire any event on Key Press, associate need to use
JavaScript.
Below the code details:
ss
oc
ia
te
ID
:4
0
if (e.keyCode==13)
{
var x = document.getElementById("<Fieldname>");
x [0].fireEvent ("<event>");
}
e: event
KeyCode: different for different key (e.g. 13 for Enter key)
Confidential
45
On If associate want to fire any event on radio button click of a list view,
associate we need to use JavaScript.
Below the code details:
ss
oc
ia
te
ID
:4
0
18
7
<script>
function <function name>(index){
httpRequestAsynch (requestURI+"? pyActivity=<Activity
name>&Parameter="+index);
}
</script>
<input type="radio" <pega: include name="ClientValidation"/>
id=<id> name=<name> class="Radio" onclick="javascript :<
function name> (<%= tools.getActive ().getParentProperty
().indexOf () %>);"/>
Confidential
46
PRPC cannot calculate the text area length properly. So, to calculate the
max length of the text area JavaScript need to use..
ss
oc
ia
te
ID
:4
0
18
7
<script>
function <function name> (obj)
{
if (obj.value.length >= <max length required>)
return false;
return true;
}
</script>
Confidential
47
narrow pane
18
7
:4
0
ss
oc
ia
te
ID
In list view after select the check all check box if user uncheck an
individual row check box. The checks all checkbox will not be unchecked.
For that scenario we need to use the JavaScript.
Confidential
48
UnselectAll ()
18
7
all_checkbox=document.getElementsByName ("check");
all_select=document.getElementsByName ("selectAll")[0];
(var i=0; i < all_checkbox.length ; i++)
:4
0
<script>
function
{
var
var
for
{
ss
oc
ia
te
ID
if (all_select.checked==true)
all_checkbox[i].checked=true;
if (all_select.checked==false)
all_checkbox[i].checked=false;
}
</script>
Confidential
49
Session Break
ss
oc
ia
te
ID
:4
0
18
7
Confidential
50
Q&A
ss
oc
ia
te
ID
:4
0
18
7
Confidential
51
ss
oc
ia
te
ID
:4
0
18
7
Confidential
52
ss
oc
ia
te
ID
:4
0
18
7
applications?
Confidential
53
Part 1 :Summary
JavaScript is a scripting language that is, parsed and executed
ss
oc
ia
te
ID
:4
0
18
7
Confidential
54
Part 2 :Summary
PRPC Out of the box features
Field validation can be used by Rule-Edit-Validate
18
7
Dynamic Select
ss
oc
ia
te
ID
:4
0
Auto Complete
Confidential
55
Part 3 :Summary
JavaScript usage in PRPC :
Increase overall user productivity on client side validation
18
7
:4
0
ss
oc
ia
te
ID
pane
Deselect/Select the check all check box in list view
Confidential
56
:4
0
18
7
ss
oc
ia
te
ID