Get the data in different Rows and push into an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 10:13 PM
Hi All,
We have a Use case where I need to get the data in 3 rows as below.
Note: Column 1 will always have same value
Column 1 Key Value
ABC cost Value 12
ABC price Value
ABC money Value56
We have written a script include and client script to get values from column 2 and 3.
Requirement is to get all details in columns 'Key' and 'Value'.
Script Include:
Tags: function() {
var keyValues = [];
var cmdbKeyGr = new GlideRecord('cmdb_key_value');
cmdbKeyGr.addQuery('configuration_item.sys_id', this.getParameter('sysparm_vmname'));
cmdbKeyGr.query();
while (cmdbKeyGr.next()) {
return cmdbKeyGr.key + cmdbKeyGr.value;
},
With this I am only getting 1st row. I need all 3 rows as output.
Please provide your inputs.
Expected Output:
Key: cost, Value: Value 12
Key: price, Value: value
Key: money, Value: Value56
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 10:11 PM
Hi,
What is your expected output?
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 10:18 PM
for Configuration Item = ABC, I want all the tagged keys and their respective values as below:
Key: cost, Value: Value 12
Key: price, Value: value
Key: money, Value: Value56
I am passing CI sys id from client side as an input to script include.
Thanks for helping...!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 10:21 PM
Hi,
Can you please check if sys_id is correctly passed to script include.
Tags: function() {
var keyValues = [];
var ci=this.getParameter('sysparm_vmname');
gs.info("Check if ci sys_id is passed: "+ci)
var cmdbKeyGr = new GlideRecord('cmdb_key_value');
cmdbKeyGr.addEncodedQuery('configuration_item='+ci);
cmdbKeyGr.query();
while (cmdbKeyGr.next()) {
var obj = {};
obj = cmdbKeyGr.key + cmdbKeyGr.value;
keyValues.push(obj);
}
gs.info('please'+ JSON.stringify(keyValues));
return JSON.stringify(keyValues);
},
Thanks and Regards,
Saurabh Gupta