Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Unable to get catalog item of current task -Business rule / email notification

Sin
Giga Expert

Hi Guys,

I have created once email notification ,it will be triggered when task is created for my ritm.

Here I need check one condition, this email notification should be triggered to only one catalog item.

So I am trying to get catalog item name through script and filter condition,both are not working. am not getting ritm value.
As another way I tried the same in background script as well to trigger event ,from there to trigger notification ,am unable to get current task's ritm number.

 

Please refer my below script which I have used in both email notification and business rule.

Table name I have choosed as : sc_task

 

Note: The Same script works in background script

 

(function executeRule(current, previous /*null when async*/ ) {
var ritm,answer;
gs.log('1' + current.number);


var tab=new GlideRecord('sc_task');
tab.addQuery('number',current.number);
tab.query();
if(tab.next()){
gs.log(tab.request_item);
ritm=tab.request_item;
}

var tab1 = new GlideRecord('sc_req_item');
tab1.addQuery('sys_id', ritm);
tab1.query();

if (tab1.next()) {
gs.log('catItem' + tab1.cat_item);
if (tab1.cat_item == '03c1fe251b018414c6e62f89bd4bcb82') {
answer = true;
} else {
answer = false;
}

}

gs.log('3' + answer);
})(current, previous);

 

Anything wrong with my code? Can anyone help me to fix this issue?

 

Thanks in Advance!

1 ACCEPTED SOLUTION

Sin
Giga Expert

Thanks for your suggestion guys.

I got the current task's catalog item name from below script added in advance script section ,

 

var answer;
if (current.request_item.cat_item.name == 'EOL') {
answer = true;
} else {
answer = false;
}

 

kindly ignore the first answer given by me.

Thanks!

View solution in original post

6 REPLIES 6

Sin
Giga Expert

Thanks for your suggestion guys.

I got the current task's catalog item name from notification filter itself by dot walking like this ,


Request Item->Show related fileds->request item fileds->catalog item fileds->Name

Sin
Giga Expert

Thanks for your suggestion guys.

I got the current task's catalog item name from below script added in advance script section ,

 

var answer;
if (current.request_item.cat_item.name == 'EOL') {
answer = true;
} else {
answer = false;
}

 

kindly ignore the first answer given by me.

Thanks!