Run a BR in list view and form

Vikram3
Giga Guru

Hello,

I wanted to execute a BR when incidents are displayed in reports and when incidents are opened. I tried all types and conditions but nothing worked. 

find_real_file.png

 

(function executeRule(current, previous /*null when async*/) {

	var openedDate = new GlideDateTime(current.opened_at);
    var endDate = new GlideDateTime();
    var statusDate = openedDate.getDate();
    var currentDate = endDate.getDate();
    var diff = GlideDateTime.subtract(openedDate, currentDate);
	var finalTime = new GlideDuration(diff);
    //var days = diff.getDisplayValue();
	current.u_days_open = finalTime;
	current.update();

})(current, previous);
9 REPLIES 9

Anil Lande
Kilo Patron

Hi,

Can you please share what you want to achieve? It would be helpful to suggest appropriate solution.

Business rules execute when any database operation is performed like Query table, Update record, delete record etc.

Also display business rule execute when a record is opened from the database and presented to user.

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Whenever an incident is displayed in the report or viewed in form a custom field should be updated.

suvro
Mega Sage
Mega Sage

when incidents are opened.

Use Display Business Rule

And using query business rule , you should only be able to modify the query.

The script that you are using can be done via scheduled job

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Whenever an incident is displayed in the report or viewed in form a custom field should be updated.

The above doesn't seem to be a valid business use-case/requirement

There could be multiple users who can view the incident report or open the record

Then how will you handle that case

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader