Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

1 REPLY 1

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('/');