I have a requirement where i have to Move the state of the demand from Submitted to Qualified state

Trupti Krishnam
Tera Contributor

I have a requirement where i have to Move the state of the demand table record from Submitted to Qualified state. when all the task that was created in the Submitted state is closed complete or Closed skipped.

 

I've written a After update business rule as below on demand_task table 

 

when state is one of 'Closed Completed / Closed Skipped '

 

   var gr = new GlideRecord('demand');
    gr.addQuery('parent', current.sys_id);
    gs.addInfoMessage("1");
    gr.query();
    while (gr.next()) {
        gr.state = '-4';
        gr.update();
    }
 
But is not working and not moving the state to Qualified Stage
9 REPLIES 9

yes i have cross checked everything.., I want to create 5 task when in State is 'Screening' after those demand tasks are approved . the system should move to the 'Qualified ' state

 

 

Musab Rasheed
Tera Sage
Tera Sage

Write After BR on demand_task table like below

(function executeRule(current, previous /*null when async*/) {
  if (current.state.changes() && (current.state == 'Closed Complete' || current.state == 'Closed Skipped')) {
    var gr = new GlideRecord('demand_task');
    gr.addQuery('parent.dmn_demand', current.parent); // or appropriate reference field
    gr.addQuery('state', 'NOT IN', 'Closed Complete,Closed Skipped');
    gr.query();
    if (!gr.hasNext()) {
      var demand = new GlideRecord('dmn_demand');
      if (demand.get(current.parent)) {
        demand.setValue('state', 'Qualified'); // or numeric value for Qualified
        demand.update();
      }
    }
  }
})(current, previous);
Please hit like and mark my response as correct if that helps
Regards,
Musab

TruptiKrishnam_2-1754578039269.png

No need to add conditions, conditions are added directly in script. My code should run. Accept the solution if that helps

Please hit like and mark my response as correct if that helps
Regards,
Musab

Trupti Krishnam
Tera Contributor

Thanks for the help !