Scripted Rules in HP SV (519 Views)
Posts: 38
Registered: ‎07-29-2008
Message 1 of 5 (519 Views)

Scripted Rules in HP SV



Can some please let me know how to use Scripted Rules in SV. And input functions are also very confusing, please let me know if any online support or documentation is available.




Frequent Advisor
Posts: 35
Registered: ‎09-03-2009
Message 2 of 5 (490 Views)

Re: Scripted Rules in HP SV

Scripted Rules are Javascript code which enables you to access the message structure directly and manipulate its values.  Before you get into the practice of scripting a rule, you should first rule out the ability to use the normal data model rules to achieve what you are looking to do. 


Even though this feature is new, too many people have jumped in scripting rather than thinking the problem through and leveraging the data model rules BEFORE starting to script.


On aspect that many new users fail to understand is how SV processes the rules.  The common (and mis-guided thought) is the rules are only processed from top to bottom and when it reaches the Default Rule, all processing is done.


This is not the case.


Let's take for example the most simple data model which has an empty Learned Rule and Default Rule (containing default responses).  Most people think that SV would pass through the rules only once but in reality, it passes through them twice.

First pass:

  • No match is found in Learned Rule
  • Match is made on the Default Rule

Since SV knows a rule was triggered, it will make a second pass to see if it can match on any rule that has NOT been triggered already.


Second pass:

  • Still no match is found in the Learned Rule
  • Default Rule has already been triggered so it is skipped

At this point, SV understands that no other possible changes could occur so it returns the values that were established when it executed the Default Rule and returns those values.


This type of processing enables you to create if/then conditions at the data level without ever having to engage in one line of code.  This is truly what "Data Driven" means and no other company has this capability.


Could you share a little bit more in what you are attempting to do with the scripting? 


Also, the objects that are accessible are noted in the comments section of the scripted rule.


Frequent Advisor
Posts: 35
Registered: ‎09-03-2009
Message 3 of 5 (430 Views)

Re: Scripted Rules in HP SV

UPDATE - new options for Scripted Rules


Right-click the scripted rule and select

Properties to display the options.


Skip the first simulation pass. To modify or complete data filled in by another rule, the

scripted rule must be have a higher priority than the rule you want to override. However, during

the first simulation pass, all the response data for the script has not yet been filled in by the

other rules. In this case, you may want to skip the scripted rule during the first simulation pass.


Execute the rule only once. As an example, you may be using the script to add an item into

an array, such as assigning an ID to a user. Each time the script is run, the rule will modify the

response, causing the simulation process to continue repeatedly. In this case, use this option

to properly execute the simulation.


This was all able to be done in the previous version as well through scripting but now this makes it easier.

Occasional Contributor
Posts: 5
Registered: ‎02-23-2015
Message 4 of 5 (156 Views)

Re: Scripted Rules in HP SV

Hi Dave,


I have a requirement to virtualize a service in which I want to sum up the values coming in request and send the same value in response.


Ex: Request is 



so I want to send the response as 

<addResponse xmlns="">
<Result>x+y</Result>            // (where x and y value should be take in run time)

Can we achieve this using data model? I am trying to implement it using javascript but facing issue.


I have used below code 



var id1=Number(hpsv.request.add.x);
var id2=Number(hpsv.request.add.y);


but I am getting error TypeError: undefined cannot be converted to an object


Can you provide me correct way to do it?


Occasional Contributor
Posts: 5
Registered: ‎02-23-2015
Message 5 of 5 (154 Views)

Re: Scripted Rules in HP SV

I have used below code


int id1=Number(hpsv.request.add.x);
int id2=Number(hpsv.request.add.y);

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.