• Home
  • Functionality
  • Functions
  • Pricing
  • News
  • Blogs
Download
Login
Skip Navigation LinksBlogs
Follow timecockpit on Twitter

How to create an action that takes parameters

By Alexander Huber in Category: time cockpit
Monday, July 26, 2010

Last week, a user brought to our attention that there was no example in our help that demonstrated how to implement an action that takes parameters. Therefore, I want to give a quick example of how to achieve the latter behavior. First let me say that the following example is rather trivial, but it should suffice to show you the basic principles of actions.

Let us say that we want to implement an action that changes the user of specific timesheets plus updates the description to leave a hint that the timesheet was updated by an action. The scenario requires four steps:

  • Creating an action
  • Creating a parameter entity for the action
  • Creating an excecution condition for the action
  • Providing source code that does the actual work

In the following, I describe the above steps in detail.

Creating an action

First we need to create a new action. Therefore, we enter the module Anpassungen and change to the “Server” context. With a right click on Actions we create a new action UpdateTimesheet.On the right pane we can set properties of the action. Under the Parameters section, we can choose between either No parameters required or Use entity as parameter type. As we want to implement an action that takes a parameter, we choose No parameters required. However, up to now, time cockpit only supports TypedParameters. That is, we must create a dedicated entity that we can use as parameter.

creating an action 

Creating an action parameter

Now we have an entity that can be used as a parameter for our UpdateTimesheet action. Hence, we can continue editing our action again. For the parameter to be available, we need to reopen the UpdateTimesheet action for editing. We can use UpdateTimesheetParameter as parameter entity for the action now. So each time users choose to execute the action, an auto-generated form for the parameter entity (a parameter dialog) is opened and users can set the values of the relation and property. Besides auto-generated forms, parameters can also have custom defined forms. A description of how to use custom forms will be covered in one of the next blog posts.

Creating an action parameter

Creating an execution condition

As we want our action to only work on timesheets, we need to define a condition under which circumstances an action should work. So we choose the Conditions section and add a new condition TimesheetCondition. Under Entity we choose APP_Timesheet. Now, we have an action that has a parameter and functions only on timesheets. Unfortunately, the action has no source code to execute. So the next step is to implement the IronPython code that does the real work.

 Creating an execution condition

Providing source code that does the actual work

The source code that does the trick looks like the following:

clr.AddReference("PresentationFramework")
clr.AddReference("System")
from System.Windows import MessageBox
def actionSample(actionContext):
  # the input set contains the selected timesheets
  for item in actionContext.InputSet:
    item.APP_UserDetail = actionContext.Parameter.NewUser
    item.APP_Description = actionContext.Parameter.NewDescription
    actionContext.DataContext.SaveObject(item)

What we do is, we iterate over all timesheets that have been selected by the user and for each timesheet we set the new user and the new description. We can access the parameter by calling actionContext.Parameter. In the context of the UpdateTimesheet action, actionContext.Parameter represents an instance of the UpdateTimesheetParameter. That is, we can call actionContext.Parameter + name of property/relation to get the values of parameter entity.

Setting the source code

Executing the action

After all the latter steps, we now can execute the UpdateTimesheet action on timesheets. For this purpose we select all timesheets that have no user set. We select the timesheets and choose UpdateTimesheet in the Actions menu.

 Executing the action

After hitting UpdateTimesheet, users are prompted for a new user and a new description in an auto-generated parameter dialog. This is where users set the parameter values that should be passed to the source code of the action. After saving the parameter, the action is executed and the timesheets are updated accordingly to the new user/description that have been entered in the parameter dialog.

Setting action parameter values

Stay tuned for the next blog post, where I will deal with how to define custom forms for action parameters.

  • Facebook
  • Twitter
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • Del.icio.us
  • NewsVine
  • Reddit
  • Blinklist
  • Add diigo bookmark

Comments  6

  • Tawny 14 Jan

    It was dark when I woke. This is a ray of sushnine.
  • Honey 15 Jan

    I love reading these atircles because they're short but informative.
  • nvvueq 15 Jan

    PePDSS , [url=http://vljkbzatkzvl.com/]vljkbzatkzvl[/url], [link=http://ursqbocgfzno.com/]ursqbocgfzno[/link], http://wfzcbqebzgmu.com/
  • qafoaidaxse 16 Jan

    oVQAi1 , [url=http://kfbhsbuhvtux.com/]kfbhsbuhvtux[/url], [link=http://xthukirhkpcb.com/]xthukirhkpcb[/link], http://riugwbiwggms.com/
  • yybsxwoj 18 Jan

    s7nwrz , [url=http://ehihbyccdbms.com/]ehihbyccdbms[/url], [link=http://delumkupaqsv.com/]delumkupaqsv[/link], http://xgzulkliwvwy.com/
  • pqnexzvgbr 19 Jan

    2ViW00 , [url=http://btjclfwaxttj.com/]btjclfwaxttj[/url], [link=http://cunhwoyblxjq.com/]cunhwoyblxjq[/link], http://emhkwlorvycd.com/
Post a comment!
  1. Formatting options
       
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
     
     
       

Bloggers

  • Alexander Huber (3)
  • Karin Huber (2)
  • Philipp Aumayr (9)
  • Rainer Stropek (40)
  • Simon Opelt (5)

Categories

  • .NET (7)
  • Azure (3)
  • IronPython (5)
  • Screencasts (12)
  • time cockpit (27)

Archive

  • 2012 (1)
    • January 2012 (1)
  • 2011 (14)
    • October 2011 (1)
    • September 2011 (1)
    • July 2011 (1)
    • June 2011 (2)
    • April 2011 (1)
    • March 2011 (2)
    • February 2011 (5)
    • January 2011 (1)
  • 2010 (25)
    • December 2010 (5)
    • November 2010 (2)
    • October 2010 (2)
    • September 2010 (2)
    • August 2010 (2)
    • July 2010 (7)
    • May 2010 (1)
    • April 2010 (2)
    • March 2010 (2)

About Us  |  Legal Notices  | © 2010 software architects gmbh. All rights reserved.