- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 10:03 AM
Hi All, I am trying to fetch data on standard report (list view) using script include.
Below is scenario :
There are two custom fields on Incident form (value - integer)
1. actual efforts (u_actual_efforts)
2. planned efforts (u_planned_efforts)
I want to fetch data comparing these two fields ; if actual efforts is more than planned efforts return incidents.
Can you please help me how to write script for the same? I want to use script Include.
Also, if there is any other way, i would also prefer using it.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2022 07:58 AM
Hi Aditya,
Use the following script include;
var CommunityAnswerEffortComparison = Class.create();
CommunityAnswerEffortComparison.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareEfforts : function(){
var array = [];
var gr = new GlideRecord('incident');
//gr.addActiveQuery();
gr.query();
while(gr.next()){
var plannedEffort = gr.getValue('u_planned_efforts');
var actualEffort = gr.getValue('u_actual_efforts');
var difference = gs.dateDiff(actualEffort, plannedEffort, true);
if(difference < 0)
array.push(gr.getValue('sys_id')+'');
}
return array.toString();
},
type: 'CommunityAnswerEffortComparisonForReport'
});
Hopefully this will fulfill your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2022 12:14 PM
Hi Aditya,
Create a script include as follows;
var CommunityAnswerEffortComparison = Class.create();
CommunityAnswerEffortComparison.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareEfforts : function(){
var array = [];
var gr = new GlideRecord('incident');
//gr.addActiveQuery();
gr.addEncodedQuery('u_actual_effortsGT_FIELDu_planned_efforts');
gr.query();
while(gr.next()){
array.push(gr.getValue('sys_id')+'');
}
return array.toString();
},
type: 'CommunityAnswerEffortComparison'
});
Following is the image of Script Include for reference.
Call it in filter condition of report as follows;
javascript:new CommunityAnswerEffortComparison().compareEfforts()
Following is the image of filter condition in report for reference.
For reference, do check following knowledge article;
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0832058
Note: You can also use condition builder (filter) in reports to fetch these records without using script.
Hopefully this will help you in creating your report.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2022 05:18 AM
Hi Muhammad Khan,
Can you help me if Field value is Duration, not Integer ? do we have to convert duration to integer and then compare values? if yes, can you help how to modify existing script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2022 07:58 AM
Hi Aditya,
Use the following script include;
var CommunityAnswerEffortComparison = Class.create();
CommunityAnswerEffortComparison.prototype = Object.extendsObject(AbstractAjaxProcessor, {
compareEfforts : function(){
var array = [];
var gr = new GlideRecord('incident');
//gr.addActiveQuery();
gr.query();
while(gr.next()){
var plannedEffort = gr.getValue('u_planned_efforts');
var actualEffort = gr.getValue('u_actual_efforts');
var difference = gs.dateDiff(actualEffort, plannedEffort, true);
if(difference < 0)
array.push(gr.getValue('sys_id')+'');
}
return array.toString();
},
type: 'CommunityAnswerEffortComparisonForReport'
});
Hopefully this will fulfill your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2022 08:22 AM
Awesome, This works Absolutely fine, I need to learn coding from you..