- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2022 10:51 PM
Hello All,
can anyone please guide me how to count affected ci on incident form and display when form load?
Thank You.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2022 11:10 PM
Hello,
Please do the below:-
Write a display BR on incident table with the below code:-
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.query();
if(rec.next()){
g_scratchpad.count=rec.getRowCount();
}
})(current, previous);
Then write a onload client script with below code:-
Now if you want to show it as a message on load use below:-
function onLoad() {
//Type appropriate comment here, and begin script below
var count=g_scratchpad.count;
g_form.addInfoMessage(count);
}
Now if you want to set it on a field on load use below:-
function onLoad() {
//Type appropriate comment here, and begin script below
var count=g_scratchpad.count;
g_form.setValue('fieldname',count);
}
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2022 11:00 PM - edited ‎12-15-2022 11:15 PM
Hi @Sagar_pawar ,
Write a display business rule doing GlideAggregate on the affected ci table and display the message using gs.addInfoMessage().
Try below code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var count = 0;
var affCIGA = new GlideAggregate('task_ci');
affCIGA.addAggregate('COUNT');
affCIGA.addEncodedQuery('task.number='+current.getUniqueValue());
affCIGA.query();
while(affCIGA.next()){
count = affCIGA.getAggregate('COUNT');
}
gs.addInfoMessage('Affected CI Count:: '+count);
})(current, previous);
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2022 11:10 PM
Hello,
Please do the below:-
Write a display BR on incident table with the below code:-
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('task_ci');
rec.addQuery('task', current.sys_id);
rec.query();
if(rec.next()){
g_scratchpad.count=rec.getRowCount();
}
})(current, previous);
Then write a onload client script with below code:-
Now if you want to show it as a message on load use below:-
function onLoad() {
//Type appropriate comment here, and begin script below
var count=g_scratchpad.count;
g_form.addInfoMessage(count);
}
Now if you want to set it on a field on load use below:-
function onLoad() {
//Type appropriate comment here, and begin script below
var count=g_scratchpad.count;
g_form.setValue('fieldname',count);
}
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 10:50 PM
Hello @Saurav11, I want to show XYZ field once we added affected ci's in related list so can you please guide me how we can do this without onload client i am trying to achieve the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2022 11:55 PM
Hi @Sagar_pawar ,
Try it with Data Policy:
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**