Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
1257 views

How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Hello Experts,

I have written a JS in Script Library for validating IP Addresses according to our environment. I would like to validate the same in device format control. How should I write the same in device FC?

Please help. Few details are below::

FC: device

Tab: Validation

Field: ip.address in $file

 

Regards,

Avi

0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

@Avi_hpsm1

function validateIPaddress(ipaddress) { 
if (ipaddress) {
return (/^(^10\.)|(^161\.)|(^172\.)|(^192\.)|(^199\.)|(^204\.)|(^217\.)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) ? ('10.0.0.0.10.10.10.10'.indexOf(ipaddress)==-1)? true:false:false
}
return false
}

Try code above lettme know if it's not working. 

If it is working for you please mark solution as accepted and give the kudo as well:) 

View solution in original post

15 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Can you show us your JS that you have in the Script Library?

0 Likes
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Hello Tompowe,

Thanks for your reply. As required, I have attached my JS along with this thread.

Please let me know your valuable inputs regarding the same.

Actually, I want to validate IP Address which is a field in CI Details form (device file). Hence, I had written one JS and would like to call the same from device fc validation along with Error Message,

 

Regards,

Avi

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Hi @Avi_hpsm1

In you fc > Validations tab 

add: true 

update: true 

Validation: jscall("validatingIPAddresses.validateIPaddress", ip.address in $file)

set focus to:  ip.address 

message : 'Any message '

your SL 

function validateIPaddress(ipaddress) {  
return (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))
}

HTH.

 

 

 

Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Hello Exeptt,

Thanks for your reply. I followed the steps. But, unfortunately, I got the attached error. Please check once.

If you see my JS, I can see that I am passing ciName as parameter. But, I have used ip.address in $file in validation. Is this the cause? I am not sure.

Please let me know your inputs.

Thanks again..

 

Regards,

Avi

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

@Avi_hpsm1

lolks like you have missed something.

share screenshot of your validation tab and js

you js function must return true / false

as exmple above.    

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

of course it will not 🙂

share you the ip ranges Ill try to write code for you.

 

 

0 Likes
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

I have sent my JS as an attachment in my earlier post. I am attaching here as well. Please have a look at it.

Along with this mail, I have attached Screenshot of my Validation tab.

 

Regards,

Avi

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

@Avi_hpsm1

your code is not returning any values and selecting file which are excessively.

share you code please not as screen shot I'll modify it for you.  

0 Likes
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Hello Exeptt,

Thanls for your reply. I tried attaching the same. But, getting an error. It seems, only jpg, gif, png are acceptable. Others are not, even zip file is not getting attached.

If possible, I can send in your mail ID. Please let me know.

Please have a look.

Thanks..

 

Regards,

Avi

0 Likes
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

Let me paste it here.

function validateIPAddress(ciName)
{
var fFile = new SCFile( "device" );
var fFileRet = fFile.doSelect("logical.name=\""+ ciName +"\"");
var var1 = fFile.ip_address;
var aNames = var1.split(".");
var len = aNames.length;

if (len == 4){
if (fFileRet == RC_SUCCESS)
{
if (aNames[0] == 10){
if (aNames[1] > 0 && aNames[1] <= 255){
if (aNames[2] > 0 && aNames[2] <= 255){
if (aNames[3] > 0 && aNames[3] <= 255){
if (aNames[1] != 10 || aNames[2] != 10 || aNames[3] != 10){
print("This is a Valid IP Address");
}
else{
print("This is an Invalid IP Address");
}
}
else{
print("This is an Invalid IP Address");
}
}
else{
print("This is an Invalid IP Address");
}
}
else{
print("This is an Invalid IP Address");
}
}
else if (aNames[0] == 161 || aNames[0] == 172 || aNames[0] == 192 || aNames[0] == 199 || aNames[0] == 204 || aNames[0] == 217){
if (aNames[1] >= 0 && aNames[1] <= 255){
if (aNames[2] >= 0 && aNames[2] <= 255){
if (aNames[3] >= 0 && aNames[3] <= 255){
print("This is an Valid IP Address");
}
else{
print("This is an Invalid IP Address");
}
}
else{
print("This is an Invalid IP Address");
}
}
else{
print("This is an Invalid IP Address");
}
}
else {
print("This is an Invalid IP Address");
}
}
}
else{
print("This is an Invalid IP Address. The length of IP Address should be 4");
}
}

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: How to validate field in FC Validation against JS (Written in SL)?

Jump to solution

@Avi_hpsm1

Try code bellow if it will not fit you requirements share the IP ranges and rules for IP format. 

function validateIPAddress(ipadress){
var aNames =  ipadress.split(".")
var len = aNames.length;
if (!len === 4){ return false }  
  if (aNames[0] != 10) { return false } 
    if (!aNames[1] > 0 && aNames[1] <= 255) { return false } 
      if (!aNames[1] > 0 && aNames[1] <= 255) { return false } 
        if (!aNames[2] > 0 && aNames[2] <= 255) { return false } 
          if (!aNames[3] > 0 && aNames[3] <= 255) { return false }
            if (!aNames[1] != 10 || aNames[2] != 10 || aNames[3] != 10) { return true } 
if (aNames[0] == 161 || aNames[0] == 172 || aNames[0] == 192 || aNames[0] == 199 || aNames[0] == 204 || aNames[0] == 217) {
  if (aNames[1] >= 0 && aNames[1] <= 255) {
    if (aNames[2] >= 0 && aNames[2] <= 255) {
      if (aNames[3] >= 0 && aNames[3] <= 255) { return true } 
    }
  }
}
return false; 
}
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.