How to fetch variables value in business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 01:05 AM
Hi All,
I have a requirement that if a Incident whose "Has breach" is true is selected from a catalog item and if it got approved then in "task_sla" table for that particular record "Breach Approval" (created this field) will be true.
For that I made a Catalog Item Which is having fields 1)Type (select box) ; --> the type is of i) Incident ii) task
Once incident is selected then a reference field 2)Incident (referenced to task_sla table and having a condition "has breach" true) will polulate.
after submitting the request if its approved then in task_sla table against this specific incident a field named "Breach Approved" will be marked as true.
I wrote one business rule for that but this is not working. Can anyone Please help me on this.
(function executeRule(current, previous /*null when async*/) {
var task_number;
// Add your code here
var gp = new GlideRecord('sc_req_item');
gp.addQuery('short_description',' Approved tasks which have breached');// Short desc of current item
gp.query();
while(gp.next()){
var type = gp.variables.sa_type;// selectbox type variable
if(type == 1){
task_number = gp.variables.sa_incident;// if user selects incident
var gr=new GlideRecord('task_sla');
gr.addQuery('task',task_number);// picks that incident record which selected from ritm
gr.query();
gs.log('ABC',gr.getRowCount());
if(gr.next()){
var gr1 = new GlideRecord('sc_item_option_mtom');
gr1.addQuery('request_item.request_state','in_process'); // checks for the approval
gr1.addQuery('request_item.short_description',"Approved has breached tasks");
gr1.query();
if(gr1.next()){
gs.log('ABC1',gr.getRowCount());
if( gr1.value==current.task.sys_id.toString()){
current.u_breached_approved='true'; // created this field in Task_Sla table
current.update();
}
}
}
}
}
})(current, previous);
Any help will be highly appreciated.
Regards,
Sreeja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 02:16 AM
Hey Sreeja,
Use var type = gp.sa_type;
instead of
var type = gp.variables.sa_type;// selectbox type variable
Let me know if this was helpful/correct
Have a lovely day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 02:18 AM
OR you can use : gp.request_item.variables.variable_name;
Let me know if this was helpful/correct
Have a lovely day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 03:55 AM
Thanks for the reply Divya. But Its not working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2017 04:07 AM
Hey Sreeja,
Is sa_type present in your sc_req_item table?