Function Split

KouassiP
Tera Contributor

Hello All , 

I'm trying to use the function Split in SN Utils to separate a CIDR (192.168.24.21/30) .

The fact is , i have an error with this function .

You will find below my commands .

In the 1st line , through the log , i can notice that i have the CIDR but after using the split command , i can't display the part of the result . 

Could you please help me on this 

 

        var AdresseIP = RITM.variables.v_dc_azure_ldz_cidr_affected_sgl;

        var Decoupage = AdresseIP.split('/' );

        gs.info("Adresse Test :" +  AdresseIP );

        console.log("TestAffichage : " +  AdresseIP );

        console.log("Decoupage : " +  Decoupage );

        console.log("IPAdress : " + Decoupage[0] );

        console.log ("MasqueSousReseau : " + Decoupage[1] ) ;

        var IP = Decoupage[0];

        var mask =  Decoupage[1];

*** Script: Adresse Test :192.168.24.21/30
*** Script: TestAffichage : 192.168.24.21/30
*** Script: Decoupage : undefined
Script execution error: Script Identifier: null.null.script, Error Description: Cannot read property "0" from undefined, Script ES Level: 0
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "0" from undefined

   script : Line(21) column(0)

     18:

     19:                   console.log("Decoupage : " +  Decoupage );

     20:

==>  21:                             console.log("IPAdress : " + Decoupage[0] );

     22:                   console.log ("MasqueSousReseau : " + Decoupage[1] ) ;

     23:                   var IP = Decoupage[0];

     24:                   var mask =  Decoupage[1];

Stack trace:

                at null.null.script:21

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It may seem unnecessary, but I've seen stranger things. Make sure the script variable contains a string before trying to execute a string method (split) on it.

var Decoupage = AdresseIP.toString().split('/');

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

It may seem unnecessary, but I've seen stranger things. Make sure the script variable contains a string before trying to execute a string method (split) on it.

var Decoupage = AdresseIP.toString().split('/');

 

adityahubli
Tera Contributor

Hello @KouassiP ,

AdresseIP.split('/') is failing because AdresseIP itself is undefined.

So the issue is NOT your split — the variable RITM.variables.v_dc_azure_ldz_cidr_affected_sgl is returning undefined.

why AddressIP is Undefined => RITM.variables only works inside Flow Designer or Catalog Client Scripts, not server-side, instead of this you can use current.variables.variableName .

If this script is running inside RITM Business Rule / Server Script:

var AdresseIP = current.variables.v_dc_azure_ldz_cidr_affected_sgl + "";

gs.info("Adresse Test :" + AdresseIP);

var Decoupage = AdresseIP.split('/');

gs.info("Decoupage : " + Decoupage);

gs.info("IPAdress : " + Decoupage[0]);
gs.info("MasqueSousReseau : " + Decoupage[1]);

var IP = Decoupage[0];
var mask = Decoupage[1];

 

if this helps you mark it  as helpful and accept as solution .

Regards,

Aditya

KouassiP
Tera Contributor

Hello Brad , You're right . I don't know how it's possible but it works and and i don't have the error anymore . 

Thank you so much