- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2022 05:04 AM
Hi,
As part of some requirement I want to store the complete form details first in a different table field as a backup.
eg. for suppose we have a incident ticket and it is in work in progress
Once it reached that state I want to have a backup of all the field values stored in some other field.
var grINC = new GlideRecord('incident');
grINC.query();
grINC.next();
var fields = grINC.getFields();
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
var obj = {};
// here I am confused how exactly i can bring all the values in the array.
}
}
gs.print('');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2022 05:14 AM
Hi Pravalika
Try this:
var grINC = new GlideRecord('incident');
grINC.addQuery('sys_id','incident_sysid_here'); //map record sysid here.
grINC.query();
if(grINC.next())
{
var arr={};
var elements = grINC.getElements();
for (var i=0; i<elements.size(); i++) {
var element = elements.get(i);
arr[element.getLabel()] = grINC.getValue(element.getName());
//gs.info("Element label is {0}, name is {1}, value is {2}", element.getLabel(), element.getName(), grINC.getValue(element.getName()));
}
gs.print(JSON.stringify(arr));
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 01:16 AM
Hi,
Thanks for the reply it worked,
Additional requirement can we remap all the data which we got into the form after particular state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-19-2023 04:35 AM
Hi ,
When i am using the script which is provided above i am getting all the fields in the table . What i required is when i open the incident form and i have 10 fields and i need only that fields. not all the fileds.