Responsive Forms - Call global function from inside JobScript{}

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
Bnash00
Posts: 2
Joined: Mon Feb 20, 2017 9:04 pm

Responsive Forms - Call global function from inside JobScript{}

Post by Bnash00 » Fri Jan 31, 2020 10:50 am

Hi All,

I am having trouble calling functions declared in Globals.ps1 from inside the JobScript{} block when using the Job Tracker framework for responsive forms. I understand the Job is running in a separate run space, and has no reference to functions declared in MainForm.psf or Globals.ps1. However, I thought it was possible to "dot source" the Globals.ps1 file inside the JobScript block which should work. When I try to dot source Globals.ps1 the file cannot be found. I then tried to use the sample function "Get-ScriptDirectory" to get the full path of the executing script. I saved this path to a variable and passed it into one of my jobs. I then used Set-Location to change the path of the new run space to the same location Get-ScriptDirectory returned. When I dot source globals.ps1, the file is found and everything works fine when running the project from inside Powershell Studio, but when I compile the project and run the .exe none of my global functions can be found, or execute at all.

I have multiple jobs that will call one or two of the same functions. I don't want to declare the same function multiple times across multiple JobScript{} blocks.

Any guidance or help pointing me in the right direction would be very appreciated.

Thank You
Ben

jvierra
Posts: 14145
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Responsive Forms - Call global function from inside JobScript{}

Post by jvierra » Fri Jan 31, 2020 12:46 pm

You cannot call external functions from a job. Jobs run in a separate instance of PowerShell so they must contain all functions that are needed. Just include the functions in the job script.

User avatar
localpct
Posts: 309
Joined: Wed Sep 09, 2015 12:53 pm

Re: Responsive Forms - Call global function from inside JobScript{}

Post by localpct » Fri Jan 31, 2020 12:55 pm

jvierra wrote:
Fri Jan 31, 2020 12:46 pm
You cannot call external functions from a job. Jobs run in a separate instance of PowerShell so they must contain all functions that are needed. Just include the functions in the job script.
Agreed... Many head bangs on this one..

User avatar
Bnash00
Posts: 2
Joined: Mon Feb 20, 2017 9:04 pm

Re: Responsive Forms - Call global function from inside JobScript{}

Post by Bnash00 » Fri Jan 31, 2020 1:28 pm

Thanks for the replies. I'll include the functions in the job script.
Ben

Post Reply