Sunday, 6 December 2009

How do I make a Groove Forms Field editable only by managers?

Being HTML and JavaScript based, Groove Forms can be customised in a number of ways. In this FAQ I want to introduce a little-known but valuable library of JavaScript functions that can be used to enhance your own forms.

If you search the Microsoft web looking for "Groove 2007 Tool Template", you will find six or seven Forms Tool templates to download. Each of these templates includes a library of JavaScript functions called common.js. If you've not downloaded them, it is worth downloading all of them. I'm going to cusomise the Proposal Tracker, so get that one at least.

Amongst the functions in common.js are a function called IsManager,which returns true if the current user is a manager of the space, and a pair of functions, EnableField and DisableField. We can use these functions inside the Groove Forms tool to implment role-based security.

Groove Forms offers a series of events where you can hook in code to customise the form to fit your business needs. Every Form within a Forms Tool has a script file named "System callouts scripts for .js". This is your main hook into what happens inside the Groove Forms tool.

In this example I'm going to cusomise the Proposal Tracking tool to allow only Managers to assign a monetary value to the Opportunity.

  1. Add the Proposal Tracking tool to a space, and choose to modify the Opportunity form.
  2. Click the Form Scripts tab. If you don't see it, click the "Show Advanced Design Features" button.
  3. Identify the systems callouts script file and open it. You'll see a drop down to pick whereabouts you want to hook into the Forms tool. Select OnAfterInitialize.
  4. The code in the OnAfterInitialize function (a call to function BidManagerForm_OnAfterInitialize ) will be shown. This code runs once a forms tool has
  5. Close the system callouts window, select the Opportunity.js script file and choose Modify.
  6. Press Ctrl-F to launch the Find dialog and type OnAfterInitialize(). Press Find Next and you'll be taken to the code that runs after the form has been initialized.
  7. Inside the try { block, add the following:

if (IsManager()) {
EnableField(cOpportunityValueNumber_Field );
}
else {
DisableField(cOpportunityValueNumber_Field );
}


This block of code checks to see if the current user is a manager. If they are, it enables the Opportunity Value number field. Else it disables it. We get the name of the field from the top of the opportunuty.js file where all the field names are defined.

Close the forms tool and try to edit the monetary value field. If you are a manager you can.