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.
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Bnash00
Posts: 3
Last visit: Fri Mar 15, 2024 3:29 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 397
Last visit: Thu Oct 27, 2022 5:57 am

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: Fri Mar 15, 2024 3:29 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
This topic is 4 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked