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

Thanks Ankur for your help with this. 

 

I ended up going a completely different route and created a After update business rule on the table. instead of passing from the inbound action i passed directly from the record i was grabbing the user_name from.

 

No worries.

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

How do we call startFlow() and pass current parameter in Client callable Script include?

Hi,

startFlow() is server side so you can include that in client callable script include

pass the parameters from client side to server side from GlideAjax

Please mark my above response as helpful

Regards
Ankur

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

I need to update some field using current in workflow Run Script activity.

Since we have to pass wfId,current,current.operation() and vars in startFlow(), and i guess we don't have access to "current" GR in client callable script include.

so can we pass current from client script to client callable script include using GlideAjax and if not, how startFlow() will be given parameters?