Display list of incidents of logged in user and show it on page using gs.addinfomessage()

lakshmi75
Tera Contributor

I have a requiremenet to Create a Business Rule that will output information about Incidents with the same Caller. When a new Incident is created, search the database for other Incidents that have the same value in the field Caller and use gs.addInfoMessage() method to display their Numbers at the top of the page.

1 ACCEPTED SOLUTION

@lakshmi

Try this:

(function executeRule(current, previous /*null when async*/ ) {
    var arr = [];
    var grI = new GlideRecord("incident");
    grI.addQuery("caller_id", current.getValue("caller_id"));
    grI.addActiveQuery();  //use this to return active incidents
    grI.query();
    while (grI.next()) {
        arr.push(grI.getValue("number"));
    }
    gs.addInfoMessage("Caller Incidents are:" + arr.toString());

})(current, previous);

Hope it helps

 

Thanks,

Murthy

Thanks,
Murthy

View solution in original post

9 REPLIES 9

Prasad Dhumal
Mega Sage
Mega Sage

Please use this script in After Business Rule

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

    // Add your code here
    var gr = new GlideRecord('incident');
    gr.addQuery('caller_id', current.caller_id);
    gr.query();
    while (gr.next()) 
	{
        gs.addInfoMessage(gr.number);
    }
})(current, previous);

shloke04
Kilo Patron

Hi,

You do not need a script for this at all. Just add the related list as below and it will automatically do the job for you:

Right click on Incident Form Layout and then select Configure

-->Related List as shown below:

find_real_file.png

Now add the Related List :Incident by Same Caller" to the Right bucket and click on Save as shown below:

find_real_file.png

Result:

This will automatically calculate the Incident by same caller and show it to you rather than writing an additional script .

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Script shared by Murthy is correct but don't you think displaying the list of incident numbers as info message is a bad idea in terms of user experience when similar functionality is available oob
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Related list approach mention by me above is much cleaner with no cost of maintaining as well in future. But up to you which ever you find the best for your query
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi Lakshmi,

If you are doing for practice purpose then it is ok.

but if you are implementing in real-time you can suggest the approach to the business which is given by @shloke04 

 

Thanks,

Murthy

Thanks,
Murthy