Extract specific value from a string field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2023 11:52 PM - edited 07-09-2023 08:51 AM
Hi All,
In the description field, I have a key value called a job, so I want to extract this job value from the description field and add it in a summary. when I try this using below script it is returning -1 value as input .
Description:
"valueString":"[ var='B0' metric='long_running_sessions_value{instance=\"10.130.\", job=\"db_node1\"}' labels={__name__=long_running_sessions_value, instance=10.130, job=prod_db_node1} value=9 ], [ var='B1' metric='long_running_sessions_value{instance=\"10.130\", job=\"b_node2\"}' labels={__name__=oracledb_long_running_sessions_value, instance=10.130, job=prod_db_node2} value=2 ]"
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 03:03 PM
Hi, OOB ‘description’ fields are strings and so valueString[0] does not exist in a standard description field, as a standalone array element or an array element that is part of a name: value pair.
Also the formatting of data within your ‘description’ may be inconsistent as I get errors if I try to instantiate the details provided as a string or an object name: value pair in a background script.
If you need to be able to extract a specific array element, then the JSON() methods should provide a solution - once you have your string format corrected, you should be able to instantiate as an object with JSON parse.
Also the string posted above does not contain “job:”
Can you clarify your field and data format and how the data is populated into the ‘description’ ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2023 08:49 PM
can you share some business requirement how that description is getting populated and how does it look?
it looks to be a json
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader