Trouble Accessing variables from inbound action

DanielCordick
Mega Patron
Mega Patron

I am having trouble accessing the variable in my inbound action from my workflow

this is my inbound action that is used to kick the workflow off.

var userEmail = email.from;

var grUser = new GlideRecord(sys_user);
grUser.addQuery('email', userEmail.tostring());
grUser.query();

if (grUser.next()) {

var userName = grUser.user_name;
var fullName = grUser.name;
}

var wflow = new Workflow();
var wfId = wflow.getWorkflowFromName("BYODDeviceOptIn") ;

var vars= {};
vars.UserName = userName;

wflow.startFlow (wfId, current, current.operation() , vars) ;

--------------------------------------------------------------------------------------------------------------------------------

In my workflow, I have tried using workflow.inputs.UserName and workflow.variables.UserName but i when i log both of those i get undefined 

 

How can i get the Value of UserName in my workflow?

 

 

1 ACCEPTED SOLUTION

Hi,

See the example here

1) Create workflow input variable

find_real_file.png

2) Then send the data like this

var inc = new GlideRecord('incident');
inc.get('8d44ecd62ff56010aedd55f62799b691');
inc.short_description = 'test';
inc.update();
var wflow = new Workflow();
var wfId = wflow.getWorkflowFromName("Incident") ;

var vars= {};

// you need to set the value in the same column name u_username

vars.u_username = 'my_id_to_workflow';

wflow.startFlow (wfId, inc, inc.operation() , vars) ;

3) Then access it like this

// u_username is the column name which you need to use to access the value

gs.info("workflow value"+ workflow.inputs.u_username);

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Did you define the workflow inputs?

you should be using workflow.inputs.UserName to get the value

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I actually didn't define any workflow inputs... should i have? would my input be UserName? type = string?

 

 

 

As per docs you need to defined the input variables

Workflow input variables

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

See the example here

1) Create workflow input variable

find_real_file.png

2) Then send the data like this

var inc = new GlideRecord('incident');
inc.get('8d44ecd62ff56010aedd55f62799b691');
inc.short_description = 'test';
inc.update();
var wflow = new Workflow();
var wfId = wflow.getWorkflowFromName("Incident") ;

var vars= {};

// you need to set the value in the same column name u_username

vars.u_username = 'my_id_to_workflow';

wflow.startFlow (wfId, inc, inc.operation() , vars) ;

3) Then access it like this

// u_username is the column name which you need to use to access the value

gs.info("workflow value"+ workflow.inputs.u_username);

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader