Push data in an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 11:05 PM
Hi All,
We have a Use case where I need to get the data in 3 rows as below.
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-06-2023 12:39 AM
Try below Updated 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()) {
var keyValue = {
key: cmdbKeyGr.key.getDisplayValue(),
value: cmdbKeyGr.value.getDisplayValue()
};
keyValues.push(keyValue);
}
return keyValues;
},
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Ayan Murshad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2023 10:28 PM
We got below output when run in background script:
[object Object],[object Object],[object Object],[object Object]
We need values in place of object.
Expected Output:
Key: cost, Value: Value 12
Key: price, Value: value
Key: money, Value: Value56
Would you please help with this?