The CreatorCon Call for Content is officially open! Get started here.

Add info message to top of list view using Before Query Business Rule

ChadLee4
Tera Contributor

I have a Before Query business rule that adds an info message to a list view.

 

I am running into an issue when the list view query uses "GROUPBY", the query seems to run twice and display the message twice.

 

Is there a workaround to this? Or a different way to add an info message to the top of a list view?

 

Code:

    var _strCurrentURL = (gs.action.getGlideURI() || "").toString();
    if (_strCurrentURL.contains("_list.do")) {
        gs.addInfoMessage("Info Message");
        }
    }
7 REPLIES 7

priyatam_pvp
Tera Guru

Use the session variable to check whether you have displayed the Info message already, refer to the below code

var _strCurrentURL = (gs.action.getGlideURI() || "").toString();
if (_strCurrentURL.contains("_list.do")) {
var messageShown = gs.getSession().getProperty("list_info_message_shown");
if (messageShown != "true") {
gs.addInfoMessage("Info Message");
gs.getSession().setProperty("list_info_message_shown", "true");
}
} else {
gs.getSession().setProperty("list_info_message_shown", "false"); //reset the variable if not on list view.
}

Please Mark it helpful

Regards
Priyatam.


Shivalika
Mega Sage
Mega Sage

Hello @ChadLee4 

 

Please add another condition that if the query contains Group by it should be skipped - 

 

var _strCurrentURL = (gs.action.getGlideURI() || "").toString();

 

if (_strCurrentURL.contains("_list.do") && !_strCurrentURL.contains("GROUPBY")) {

    gs.addInfoMessage("Info Message");

}

 

This should work, because the BR is already executing once so It won't execute next time when groupBy is done. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Thank you for the response -- That makes the message to not display at all when a GroupBy list query is run.

Hello @ChadLee4 

 

That's a simple tweak, you can add another line 

 

current.addQuery('sys_id' , '!=', '0'); 

 

This will make the query run again and that too without group by. And it will not modify anything. Or even you can take the existing query and add encoded query. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

 

 

Regards,

 

 

 

Shivalika 

 

 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

 

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY