Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Can OnTaskFailure Access Variables set in Task?
Topic Summary:
Created On: 07/20/2018 10:00 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 07/20/2018 10:00 AM
User is offline View Users Profile Print this message

Author Icon
DaveWest
Student (5-19 posts)

Posts: 14
Joined: 12/22/2017

Is there a way for the OnTaskStart, OnTaskEnd and OnTaskFailure events to access variables created/set within the actual task steps?
 07/20/2018 01:12 PM
User is offline View Users Profile Print this message

Author Icon
Hamid Noorbakhsh
HelpSystems

Posts: 454
Joined: 07/29/2008

Dave,
Function variables are not accessible outside that function. If you need to access them from different functions/events try declaring them as Task Variables instead. Usage is the same, however they will be accessible throughout.

If you so create a variable with the same name as a Task Variable in a function, you can access it by just using it's name (since the variable resolution bubbles outwards, or _Local.myVariableName to be explicit) and _Task.myVariableName to use the higher up level variable. I hope this makes sense.

-------------------------
Thank you for choosing AutoMate

Hamid Noorbakhsh | Senior Software Engineer
AutoMate | A Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
 07/23/2018 09:12 AM
User is offline View Users Profile Print this message

Author Icon
DaveWest
Student (5-19 posts)

Posts: 14
Joined: 12/22/2017

I'm not sure I follow, Hamid...and maybe I'm going about this all wrong.

I want to set one or more variables within the Main function and then at OnTaskEnd or OnTaskFailure be able to write the values of those variables to a text file. I am getting an error saying the variables do not exist, but they do exist at least at the function level. So how can I do this?
 07/23/2018 10:08 AM
User is offline View Users Profile Print this message

Author Icon
Hamid Noorbakhsh
HelpSystems

Posts: 454
Joined: 07/29/2008

Dave,
On top above 'main' there is small menu -> 'Functions' 'Events' 'Task Variables'. You will need Task Variables (these are accessible everywhere on the task). Declare the variables you want to access everywhere in the task there. Once declared, they can accessed all throughout the task. You can declare even your dataset that is created by steps there, and if the name exists, step will populate that dataset.

I hope this makes sense., otherwise let me know and I will explain more in detail.

-------------------------
Thank you for choosing AutoMate

Hamid Noorbakhsh | Senior Software Engineer
AutoMate | A Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700

Edited: 07/23/2018 at 10:16 AM by Hamid Noorbakhsh
 07/24/2018 07:55 AM
User is offline View Users Profile Print this message

Author Icon
DaveWest
Student (5-19 posts)

Posts: 14
Joined: 12/22/2017

When I read your comment - "variable resolution bubbles outwards..." I understood that to mean that OnTaskFailure and/or OnTaskEnd would be able to access variables created and set in Main function as long as they are scoped with "_local." - ie: _local.myVariableName. Did I understand correctly?
 07/24/2018 08:13 AM
User is offline View Users Profile Print this message

Author Icon
Hamid Noorbakhsh
HelpSystems

Posts: 454
Joined: 07/29/2008

Dave,
I am sorry, I might have explained it wrong. By bubbling up, I mean if you ask the task to look up a variable named myVariable, it first looks to see if it exists locally in the function, if not then it looks at task variables, then system (constants). if a variable name exists in all three context, then to use the Task Variable explicitly, you would have to use _Task.myVariable. Task Variables are used all throughout the task, so if you want to access a variable all across declare them as Task Variable and use them everywhere.

-------------------------
Thank you for choosing AutoMate

Hamid Noorbakhsh | Senior Software Engineer
AutoMate | A Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
 07/24/2018 08:19 AM
User is offline View Users Profile Print this message

Author Icon
DaveWest
Student (5-19 posts)

Posts: 14
Joined: 12/22/2017

Thank you, Hamid - that helps. Can task variables be accessed by other tasks? In other words, if I've got a task variable named "TaskResult" in 10 different tasks, is there something that prevents task #2 from referencing task #8's "TaskResult" variable if the tasks run at the same time?
 07/24/2018 08:27 AM
User is offline View Users Profile Print this message

Author Icon
Hamid Noorbakhsh
HelpSystems

Posts: 454
Joined: 07/29/2008

Sorry Dave, the variables are not shared across tasks. Each task runs atomically on it's own. Automate Enterprise with Workflows allows for sharing variables. As a workaround, you can write your variables to a file and read on next task launch?

-------------------------
Thank you for choosing AutoMate

Hamid Noorbakhsh | Senior Software Engineer
AutoMate | A Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
 07/24/2018 10:36 AM
User is offline View Users Profile Print this message

Author Icon
DaveWest
Student (5-19 posts)

Posts: 14
Joined: 12/22/2017

Understood Hamid, thanks. What purpose does the "Private/public" setting serve on task variables?
 07/24/2018 10:46 AM
User is offline View Users Profile Print this message

Author Icon
Hamid Noorbakhsh
HelpSystems

Posts: 454
Joined: 07/29/2008

Dave, if you start a subtask from a task, Task Variables 'should' still be available if they are public. This is beyond my expertise in the running engine. Since AMTB is shared between both Automate and Enterprise products, some setting might not be used or make any difference on how they are set in one or the other (or it does not matter which one you use)

-------------------------
Thank you for choosing AutoMate

Hamid Noorbakhsh | Senior Software Engineer
AutoMate | A Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 361 guests browsing this forum, which makes a total of 361 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2019 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog