Count Affected CIs on incident form

Sagar_pawar
Tera Contributor

Hello All,

can anyone please guide me how to count affected ci on incident form and display when form load?

Thank You.

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please do the below:-

 

Write a display BR on incident table with the below code:-

 

Saurav11_0-1671174544869.png

 

 

(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. 

View solution in original post

6 REPLIES 6

reshmapatil
Tera Guru

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**

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please do the below:-

 

Write a display BR on incident table with the below code:-

 

Saurav11_0-1671174544869.png

 

 

(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. 

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.

Hi @Sagar_pawar ,

 

Try it with Data Policy:

reshmapatil_0-1671350124381.png

 

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**