Run Flow Designer with business rule for Service Catalog trigger

akyadav
Tera Expert

Hi Team,

I am trying to run one flow designer(with Service Catalog trigger) with business rule.

Business Rule Details: table: sc_req_item, type: before, Insert: true

 

Below is the script which I tried, and it is working for a single record, but I want to run flow designer for every current records which are getting inserted.

When I am passing current.sys_id in get function, it is giving me 'Incorrect GlideRecord input' error.

 

 

 

(function executeRule(current, previous /*null when async*/ ) {

    try {
        var glideRecordInput = new GlideRecord('sc_req_item');
        glideRecordInput.get('some sys id');
        var flowInputs = {};
        flowInputs['request_item'] = glideRecordInput;
        flowInputs['table_name'] = glideRecordInput.getTableName();
        var result = sn_fd.Flow.startAsync('global.employee_termination_vendor_email_flow', flowInputs); //
        var contextId = result.contextId; //The Sys ID of a flow execution (contextId)

    } catch (ex) {
        var message = ex.getMessage();
        gs.log('Flow Error: ' + message);
    }


})(current, previous);

 

 

Let me know how can I fix this.

 

Thanks!

1 ACCEPTED SOLUTION

akyadav
Tera Expert

I have changed the type to after and passed the current record sys id to resolve this issue.

View solution in original post

2 REPLIES 2

akyadav
Tera Expert

I have changed the type to after and passed the current record sys id to resolve this issue.

akyadav
Tera Expert

Change the BR type to after and use below code.

(function executeRule(current, previous /*null when async*/ ) {

    try {
        var glideRecordInput = new GlideRecord('sc_req_item');
        glideRecordInput.get(current.sys_id);
        var flowInputs = {};
        flowInputs['request_item'] = glideRecordInput;
        flowInputs['table_name'] = glideRecordInput.getTableName();
        var result = sn_fd.Flow.startAsync('global.employee_termination_vendor_email_flow', flowInputs); //
        var contextId = result.contextId; //The Sys ID of a flow execution (contextId)

    } catch (ex) {
        var message = ex.getMessage();
        gs.log('Flow Error: ' + message);
    }


})(current, previous);