I want to write the BR to trigger the approval

PRAGHATIESH S
Tera Expert

Hi,

I want to trigger the approval to "XY" group, if requested for ( all catalog item) manager is empty. Can anyone help here to write the business Rule

3 REPLIES 3

Tai Vu
Kilo Patron
Kilo Patron

Hi @PRAGHATIESH S 

You can consider to have a flow and set according trigger condition to start.

In the other hand, if you wanna start the flow within business rule by some specific reason that can't be handled by the trigger condition, you can use the FlowAPI.

startFlow(String name, Map inputs)

(function() {
 
  var now_GR = new GlideRecord('incident'); 
  now_GR.addQuery('number', 'INC0009009'); 
  now_GR.query(); 
  now_GR.next();

  try {
    var inputs = {};
    inputs['current'] = now_GR; // GlideRecord of table: Incident
    inputs['table_name'] = 'incident';

    var contextId = sn_fd.FlowAPI.startFlow('global.test_flow', inputs);	
	
  } catch (ex) {
    var message = ex.getMessage();
    gs.error(message);  
  }
})();

 

Cheers,

Tai Vu

Mark Manders
Mega Patron

Why a business rule? Service Requests are handled through (work)flows (OOB) and all logic for approval is in preconfigured actions/activities. Just creating a BR to create an approval record, will also mean that all other logic needs to be created outside the (work)flow. Just get the requested for within the (work)flow, check on its manager and if none, create the approval for the group.

And what didn't work in the solution you accepted on this question: https://www.servicenow.com/community/developer-forum/need-to-create-a-subflow/td-p/3106811

It is exactly what you are asking for.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Harish Murikina
Tera Guru

Hi @PRAGHATIESH S 

Please create Business rule on table sc_req_item. and give condition for Business rule to trigger, 

Script :

var approvalGr = new GlideRecord("sysapproval_group")
approvalGr.initialize();
approvalGr.setValue("assignment_group", "Group_sys_id");
approvalGr.setValue("approval", "requested");
approvalGr.setValue("parent", current.getUniqueValue() );
approvalGr.insert();