- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 12:48 AM
Hi Team
I want to get details from Incident form in below format:
Number:
State:
Category:
Caller:
Priority:
How can I get the details from script ,or get the result from background script.
Thanks in Advance
Souvick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:50 AM
Hi @Souvick6917
var incidentGR = new GlideRecord('incident');
// use this to filter your incidents --> incidentGR.addQuery('field', 'value');
incidentGR.query();
var incidents = [];
while (incidentGR.next()) {
// Construct an object for each record with the desired details
var incidentDetails = {
number: incidentGR.getValue('number'),
state: incidentGR.getDisplayValue('state'),
category: incidentGR.getValue('category'),
caller: incidentGR.getDisplayValue('caller_id'),
priority: incidentGR.getDisplayValue('priority')
};
incidents.push(incidentDetails);
}
// Convert the array of incident objects to a JSON string
var incidentsJson = JSON.stringify(incidents);
// Print the JSON string to the log
gs.info(incidentsJson);
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 12:55 AM
Hi Souvick,
Please use the following code:
var incidentRecord = new GlideRecord('incident');
incidentRecord.get('sys_id'); //use incident record sys_id here
var number = incidentRecord.number;
var state = incidentRecord.state.getDisplayValue();
var category = incidentRecord.category.getDisplayValue();
var caller = incidentRecord.caller.getDisplayValue();
var priority = incidentRecord.priority.getDisplayValue();
// Output details
gs.info("Number: " + number);
gs.info("State: " + state);
gs.info("Category: " + category);
gs.info("Caller: " + caller);
gs.info("Priority: " + priority);
Please let me know if you need anything else.
Thanks,
Brahmjeet
Please mark as helpful or solution accepted if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:30 AM
Thank you for your reply. But in this case I have to provide the sysid of the incident, I want dynamic value from the incident table with out providing the incident sysid. I have heard of of solution for this through JSON, can you help me with that code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:50 AM
Hi @Souvick6917
var incidentGR = new GlideRecord('incident');
// use this to filter your incidents --> incidentGR.addQuery('field', 'value');
incidentGR.query();
var incidents = [];
while (incidentGR.next()) {
// Construct an object for each record with the desired details
var incidentDetails = {
number: incidentGR.getValue('number'),
state: incidentGR.getDisplayValue('state'),
category: incidentGR.getValue('category'),
caller: incidentGR.getDisplayValue('caller_id'),
priority: incidentGR.getDisplayValue('priority')
};
incidents.push(incidentDetails);
}
// Convert the array of incident objects to a JSON string
var incidentsJson = JSON.stringify(incidents);
// Print the JSON string to the log
gs.info(incidentsJson);
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma