Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Inputs to flow designer script is not working

Kavya16
Tera Expert

Dear All,

I tried to write a script for task sla table, but its not  accepting the inputs if i provide the sys_id..Please help. It says input is invalid. Trigger of my flow is task sla.

var inputs = {};
inputs['sys_id'] = '23f306c4dbc7c1d0f328a05605961910';
var result = sn_fd.FlowAPI.getRunner() 
.flow('global.test123')
.inBackground() 
.withInputs(inputs)
.run(); // 

var contextId = result.getContextId();
gs.info(contextId)

 

Kind Regards,

Kavya

5 REPLIES 5

Jorn van Beek
Tera Guru

Flows do not accept inputs.

Inputs are used for when you trigger an action or a subflow.

See example flow from documentation

(function() {
  try {

    var result = sn_fd.FlowAPI.getRunner()
      .flow('global.test_flow')
      .inForeground()
      .run();

    gs.info(result.debug());

  } catch (ex) {
    var message = ex.getMessage();
    gs.error(message);
  }

})();

 

Hi Jorn,

When I tried to run the script from background script, I get error that invalid task_sla record , I'm wondering I can I pass the sys_id of the record to the flow to trigger. Please help,

 

Thanks,

Kavya

Hi Kavya,

I am not sure but I think it takes the current record as current. so you should run the script from a br triggered by the task_sla record.

Otherwise

Change the flow to a subflow then you can use inputs.

Note:

In my tests the inputs were always a string. If I wanted to use a record I provide the string and first action in the subflow was look up record. After that I could use that record.

Hi Jorn,

 

when copy the flow code snippet. I get the below code , I tried to pass as current for both the inputs but flow is not triggers from br.

try {
var inputs = {};
//inputs['sla_flow_inputs'] = current; // Object
inputs['task_sla_record'] = current;

// Start Asynchronously: Uncomment to run in background.
sn_fd.FlowAPI.getRunner().flow('sn_slack_ah_v2.sn_slack).inBackground().withInputs(inputs).run();

// Execute Synchronously: Run in foreground.
//sn_fd.FlowAPI.getRunner().flow('sn_slack_ah_v2.sn_slack).inForeground().withInputs(inputs).run();

} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}

In the logs I see below as input

 

{"task_sla_record":{"sys_meta":{"active":"1","array":"0","attributes":"hasLabels=true","audit":"0","calculation":"","choice":"1","choice_field":"","choice_table":"","create_roles":"","default_value":"","delete_roles":"","dependent":"","dependent_on_field":"","display":"sla","dynamic_creation":"0","dynamic_creation_script":"","dynamic_default_value":"","dynamic_ref_qual":"","element_reference":"0","filterable":"1","foreign_database":"","function_definition":"","function_field":"0","groupable":"1","help":"","hint":"","i18n_sortable":"1","internal_type":"collection","label":"Task SLA","language":"en","mandatory":"0","matchable":"1","max_length":"40","multi_text":"0","name":"task_sla","plural":"Task SLAs","primary":"0","read_only":"0","read_roles":"","reference":"","reference_cascade_rule":"","reference_floats":"0","reference_key":"","reference_qual":"","reference_qual_condition":"","reference_type":"","sizeclass":"34230998","sortable":"1","spell_check":"0","staged":"0","sys_package":"1d373f164f03020021929dde0310c71c","sys_scope":"global","table_reference":"0","text_index":"0","type":"0","type_description":"collection","unique":"0","url":"","url_target":"","use_dynamic_default":"0","use_reference_qualifier":"simple","virtual":"0","widget":"","write_roles":"","xml_view":"0"},"pause_duration":{},"pause_time":{},"timezone":{},"sys_updated_on":{},"business_time_left":{},"duration":{},"sys_id":{},"time_left":{},"sys_updated_by":{},"sys_created_on":{},"percentage":{},"original_breach_time":{},"sys_created_by":{},"business_percentage":{},"end_time":{},"sys_mod_count":{},"active":{},"sla":{},"business_pause_duration":{},"sys_tags":{},"start_time":{},"schedule":{},"task":{},"business_duration":{},"stage":{},"planned_end_time":{},"has_breached":{}}}

 

Thanks,

Kavya