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

Notification on sc_task table

prl1120
Kilo Explorer

Hello,

I have a notification on sc_task table where I am trying to add a condition, when the request item is on specific stage, notification should trigger.

So far I have included the condition with the AND statements provided:

Request item.Stage contains 'Stage Name'

but notification doesn't seem to triggered.

I have also tried including it as an advanced condition, with following script:

var answer = false;

condition();

function condition(){

  var gr = new GlideRecord('sc_req_item');

  gr.addQuery("sys_id",current.request_item);

  gr.query();

  if(gr.next()){

            if(gr.stage == 'Stage Name''){

                      answer = true;

            }

  }

  return answer;

}

I have used a similar script on other notification and they work fine. The only difference is that working notifications are calling on approvals table and above calls on the tasks.

I am not great at scripting, and I get the sense the addQuery might be wrong. Please help.

Thank you so much in advance.

13 REPLIES 13

russell_miller
Kilo Guru

Looks like you have quotes mismatched



            if(gr.stage == 'Stage Name''){



should be



            if(gr.stage == 'Stage Name'){



Hope that helps



R


Tanaji Patil
Tera Guru

I tried with the condition builder but don't know why it is not displaying the stage choices is it.


But you can do it using the advanced condition provided in the Notification. Use below code-



if(current.request_item.stage == 'value_of_stage_choice')   //it should be values and not the name here


        answer = true;


else


        answer = false;




You don't need to declare the answer variable neither you need to return it.


Paste the above code as it is and just replace the 'value_of_stage_choice' with the actual stage value in the if condition.




Thanks,


Tanaji


Hello Tanaji,


I tried the code, for some reason Stages are not being picked up in the notifications, not even through the script. Could it be something related to the workflow or how stages were created?


arnie
Mega Contributor

Make sure you are picking the value of the stage than the label. For e.g. if you want to compare the stage 'Waiting for Approval' then the comparison should be with the value 'waiting_for_approval'.