Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Extract report from Incident form

Souvick6917
Tera Contributor

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

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage
Kilo Sage

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 


View solution in original post

3 REPLIES 3

BrahmjeetTanwar
Tera Guru

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.

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.

Deepak Shaerma
Kilo Sage
Kilo Sage

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