Need to remove square brackets

TejasviR
Tera Contributor

Hello Everyone!

 

I am getting sys id after glide hit and storing in a variable, but when I print that variable sys_id is showing in brackets. I want to remove those square brackets from the sys_id.

var b = ac_ci;

gs.print(b);

 

Output: b = [bfb9f882db38] {i want to remove these brackets}

I already tried the regex method but had no luck.

 

Thanks in advance

 

9 REPLIES 9

Swapna Abburi
Mega Sage
Mega Sage

@TejasviR 

You may try Replace method.

var b = ac_ci;
b = b.replaceAll(']','').replaceAll('[','');
gs.print(b);

Hello @Swapna Abburi 

 

Thank you for your reply, i already tried this. its shows me 'undefined'.

@TejasviR 

Please post your complete script if possible.

This is my script:

 

var a_req = new GlideRecord('sc_req_item');
a_req.addEncodedQuery('sys_id=1366f13d87c0e11013c743360cbb3557');
a_req.query();
if(a_req.next()){
    var ci_name = a.variables.ip_address_and_server_info.source_server;
    var b = ci_name;
    gs.print(b);
    b  = b.replaceAll(']','').replaceAll('[','');
    gs.print(b);

    var cm = new GlideRecord('cmdb_ci');
    cm.addEncodedQuery('sys_id=bfb9f882db38c450a8dc7dba8c9619b7');
    gs.print("Hello");
    cm.query();
     gs.print("Hello 123");
    if(cm.next()){
        gs.print("1452");
    }
  }