Responsive Forms - Call global function from inside JobScript{}

Ask your 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.
Locked
User avatar
Bnash00
Posts: 3
Last visit: Thu Feb 10, 2022 1:06 pm
Has voted: 1 time
Been upvoted: 1 time

Responsive Forms - Call global function from inside JobScript{}

Post by Bnash00 »

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: 15285
Last visit: Sat Sep 24, 2022 12:01 pm
Answers: 26
Has voted: 4 times
Been upvoted: 27 times

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

Post by jvierra »

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: 394
Last visit: Thu Sep 15, 2022 1:44 pm

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

Post by localpct »

jvierra wrote: Fri Jan 31, 2020 11:46 am 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: 3
Last visit: Thu Feb 10, 2022 1:06 pm
Has voted: 1 time
Been upvoted: 1 time

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

Post by Bnash00 »

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