Trim specific string from sc_task's description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 01:13 AM - edited 12-28-2023 01:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 01:23 AM
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