# system.util.invokeLater with Arguments

**URL:** <https://forum.inductiveautomation.com/t/system-util-invokelater-with-arguments/4224>\
**Category:** General Discussion\
**Created:** [March 29, 2012, 7:04pm UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-with-arguments/4224 "2012-03-29T19:04:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 29, 2012, 7:04pm UTC](https://forum.inductiveautomation.com/t/system-util-invokelater-with-arguments/4224/1 "2012-03-29T19:04:43Z")

</div>

system.util.invokeLater can be awkward to use when you need to pass in arguments to the function that will be called.

That’s why I wrote the function app.util.invokeLaterWithArgs().

This function works the same way as system.util.invokeLater except you can pass in positional or keyword arguments for the function that will run, and it will still be invoked later.

Here is an example of its use:

Some function like the setNum function could be defined somewhere:

```auto
def setNum(e,num):
  e.source.text = num
```

Then setNum could be invoked later with keyword arguments like this:

```auto
app.util.invokeLaterWithArgs(setNum,e=event,num=55)
```

Or it could be invoked later with positional arguments like this:

```auto
app.util.invokeLaterWithArgs(setNum,event,55)
```

Here is the code that implements app.util.invokeLaterWithArgs()

```auto
def invokeLaterWithArgs(f,*args,**kwargs):
  def func(f=f,args=args,kwargs=kwargs):
    f(*args,**kwargs)
  system.util.invokeLater(func)
```

You might need to add “import system” to the invokeLaterWithArgs function. I didn’t because I usually add this to the top of all my Jython modules:

```auto
global system,app
import system,app
```
