Trim specific string from sc_task's description

Dolly M
Tera Guru

We have below text in sc_task description. It is kind of a key-value pair description.

We need to get the values of CI class, Device Type, IP address, Serial Number etc.. so that I can use them in BR to auto-update the data in cmdb table. How can I use splie, substr, substring functions here ?

 

 

Installation Details - Device 2
-------------------------------------------------------------------------
CI Class : Network Gear
Device Type : Network ROuter
IP Address : 10.X.X.X
Serial Number : d
Make : d
Model : d
Network Criticality : Medium
Environment : DR
Location : ABC Branch
Owned By : ABC User
Are EOL/EOS dates available : No
End of Life : N/A
End of Support : N/A
Firmware Version : s

1 REPLY 1

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi @Dolly M 
I am assuming the above string is in the description field of incident record.

var t=new GlideRecord('incident');
t.get('4207c4e7070bf5105295f19d7c1ed061');

var str=t.getValue('description').trim();
var substrn=str.split("\n");
var retArr=[];
for(var i=0;i<substrn.length;i++)
{
    var tempStr=substrn[i].split(":");
    var obj={};
 obj[tempStr[0].trim()]=tempStr[1].trim();
 retArr.push(obj)
}

gs.info(JSON.stringify(retArr,null,3))

Thanks and Regards,

Saurabh Gupta