How to trigger notification based on advance condition

avinashdubey103
Tera Guru

Hi , i have a requirement to trigger the notifications based on the the catalog item is present in system property file 

I have written a script include and calling that into the advance condition of notifications but its not working 

Script include :

 isCatalogItemIncluded: function(current) {
       var listOfVariables = gs.getProperty('NotificationImprovement_ListofCatlogItemtoInclude');
       if (listOfVariables && listOfVariables.indexOf(current) !=-1) {
           return true;
       }
       return false;
   },
 
Advance condition :


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


    var catalogItemId = current.variables.cat_item.toString();


    var ga = new GlideAjax('displayRitmVariables');

    // Add parameters to the GlideAjax object

    ga.addParam('sysparm_name', 'isCatalogItemIncluded');

    ga.addParam('sysparm_currentCatalogItem', catalogItemId);



    ga.getXMLAnswer(function(response) {

        var isItemIncluded = response == 'true'; // Convert the response to a boolean value

        if (isItemIncluded) {

            if (current.priority == 1) {

                current.setAbortAction(false); // Ensure notification is not aborted
            }
        } else {
            // If the catalog item is not included, abort the notification
            current.setAbortAction(true);
        }

    });


})(current, previous);

 

1 ACCEPTED SOLUTION

Subhashis Ratna
Tera Guru

Hi @avinashdubey103 

I have updated and retested your code, and it's fine. So, you need to pass the sys_id of the record like this.

Demo Sys_Property :

SubhashisRatna_1-1712378522161.png

Updated code : 

 

SubhashisRatna_0-1712378447129.png

Script include Code :

 

 

isCatalogItemIncluded: function(currentsysID) {
    var listOfCatalogItems = gs.getProperty('NotificationImprovement_ListofCatlogItemtoInclude');
    if (listOfCatalogItems && listOfCatalogItems.includes(currentsysID)) {
        return true;
    }
    return false;
},

 

 

Based on the return value, you can use this code in a notification script like this :-

SubhashisRatna_3-1712380379710.png

 

 

 

var answer = false;
var catalogItemId = current.variables.cat_item.toString();
var checker = new CatalogItemInclusionChecker();
var isItemIncluded = checker.isCatalogItemIncluded(catalogItemId);

if (isItemIncluded) {
    if (current.priority == 1) {
        answer = true;
    }
}

 

 

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna

View solution in original post

3 REPLIES 3

subhadeep1618
Tera Guru

Hi @avinashdubey103 ,

First of all when do you want to trigger the notification?

If you want to trigger it when a service request is opened, then you have configure the notification event properly.

  1. Create a new notification.
  2. Table = Requested Item [sc_req_item]
  3. Send when = event is fired
  4. Event name = sc_req_item.inserted
  5. Then in the Advanced condition, write the following script
var gr = new GlideRecord('sys_properties');
gr.addQuery('value',current.cat_item.sys_id);
gr.query();
if(gr.next())
	return true;

return false;

Here the value field is the sys_id of the record object added in the system properties.

You don't need the script include or business rules.

Let me know if this works for you.


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.

thanks for the reply , 

I have created system property and added the catalog item id in that 

how will this gliderecord fetch that 

Please suggest

Subhashis Ratna
Tera Guru

Hi @avinashdubey103 

I have updated and retested your code, and it's fine. So, you need to pass the sys_id of the record like this.

Demo Sys_Property :

SubhashisRatna_1-1712378522161.png

Updated code : 

 

SubhashisRatna_0-1712378447129.png

Script include Code :

 

 

isCatalogItemIncluded: function(currentsysID) {
    var listOfCatalogItems = gs.getProperty('NotificationImprovement_ListofCatlogItemtoInclude');
    if (listOfCatalogItems && listOfCatalogItems.includes(currentsysID)) {
        return true;
    }
    return false;
},

 

 

Based on the return value, you can use this code in a notification script like this :-

SubhashisRatna_3-1712380379710.png

 

 

 

var answer = false;
var catalogItemId = current.variables.cat_item.toString();
var checker = new CatalogItemInclusionChecker();
var isItemIncluded = checker.isCatalogItemIncluded(catalogItemId);

if (isItemIncluded) {
    if (current.priority == 1) {
        answer = true;
    }
}

 

 

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

Thanks,
Subhashis Ratna