Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE
Highlighted
Absent Member.. Anu_Madan Absent Member..
Absent Member..
642 views

Can the custom functions be configurable?

Jump to solution

I want to define a custom function and specify that $input_string should be between a range of values. 

eg. (id <= 5  and id >= 2), is there a way to define variables and define this function as (id <= var1 and id >= var2)?

So that, if needed, these values can be changed from time to time.. is such flexibility possible?

Can there be any external configuration file?

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: Can the custom functions be configurable?

Jump to solution

$input_int > 1 AND $input_int < 3

I suggest you use $input_int (rather than $input_string) since your example is using integers rather than strings.

you are not able to create arguments the way you are asking for below using the custom functions in the SV Designer UI

Here are a few approaches I have used to be able to easily swich and change things like you are looking for.

1) You can create multiple functions like below and just select which one to be used when needed.

"between 1 and 3" -> "$input_int > 1 AND $input_int < 3"

"between 2 and 5 inclusive" -> "$input_int >= 1 AND $input_int <= 5"

"between 6 and 10 inclusive" -> "$input_int >= 6 AND $input_int <= 10"

2) Similar to the above, but I created a rule for each one of the functions and then just enable the rule I wish to use which has the function I need.

3) Create a scripted rule to read from a source and perform the actions needed.  In this case you wouldn't use the custom function as you have (or I mentioned in #1).  I have only had the need to use this approach once so far.

Remember, you can easily just go and edit the function to have which ever new values you need since it is "from time to time" that they need to be changed.  To do this, in the Virtualization Explorer on the left side, expand <virtual service>->Data Model->Functions.  Right click on the function you want to edit and select edit.

If you are not seeing the Virtualization Explorer on the left, then from the menu bar, select View->Virtualization Explorer

0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

Re: Can the custom functions be configurable?

Jump to solution

$input_int > 1 AND $input_int < 3

I suggest you use $input_int (rather than $input_string) since your example is using integers rather than strings.

you are not able to create arguments the way you are asking for below using the custom functions in the SV Designer UI

Here are a few approaches I have used to be able to easily swich and change things like you are looking for.

1) You can create multiple functions like below and just select which one to be used when needed.

"between 1 and 3" -> "$input_int > 1 AND $input_int < 3"

"between 2 and 5 inclusive" -> "$input_int >= 1 AND $input_int <= 5"

"between 6 and 10 inclusive" -> "$input_int >= 6 AND $input_int <= 10"

2) Similar to the above, but I created a rule for each one of the functions and then just enable the rule I wish to use which has the function I need.

3) Create a scripted rule to read from a source and perform the actions needed.  In this case you wouldn't use the custom function as you have (or I mentioned in #1).  I have only had the need to use this approach once so far.

Remember, you can easily just go and edit the function to have which ever new values you need since it is "from time to time" that they need to be changed.  To do this, in the Virtualization Explorer on the left side, expand <virtual service>->Data Model->Functions.  Right click on the function you want to edit and select edit.

If you are not seeing the Virtualization Explorer on the left, then from the menu bar, select View->Virtualization Explorer

0 Likes
Absent Member.. Anu_Madan Absent Member..
Absent Member..

Re: Can the custom functions be configurable?

Jump to solution

Thanks Dave.

Unfortunately, I do not have any ranges defined for which I can create multiple functions now. So points 1 and 2 are not options for me.

I have as of now created a function with any integer values defined as range and am planning to instruct the team to change the values as and when needed as you suggested in the end of your response.

The 3rd option seems interesting. Could you please point me to some example where scripted rule can read from a source? Also, what type of source this can be?

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Can the custom functions be configurable?

Jump to solution

It sounds like you are jumping to the coding/scripting solution too fast but it is tough for me to make that judgement since I don't know the specifics of your circumstance or what your model lookd like.

I will assume you have read the User Guide as a staring point and know you have the option of Javascript or C# as scripting languages and then I would point you to the following posts:

I would also suggest you explore the use of a Data Source rule where you can map the fields to Excel spreadsheets.  This makes it very easy to cahnge/update data models without having to do any coding.  I have used this along with Excel's data query tool when we wanted to pull data from production databases to be used as part of the data to be used by the virtual service.

 

0 Likes
Absent Member.. Anu_Madan Absent Member..
Absent Member..

Re: Can the custom functions be configurable?

Jump to solution

Hi Dave,

I tried following the samples you suggested. The HPSV version we are using in 3.61.

I could only see the enable scripting options as javascript rules. C# options are not visible. It also mentiones 'Scripting rule (BETA)' in the options while creating the new rule.

Is it possible to connect to the DB or write to files using javascript script rules. Any samples you have for enabling the sql packages in configuration files for version 3.61?

Your help will be greatly appreciated.

Thanks in advance.

Regards,

Anu

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.