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.

Monday, 14 January 2008

Bambuco Desktop gains Microsoft Certification

 

late last year, we submitted Bambuco for testing, and I'm pleased to report that

"Bambuco Desktop has been tested and meets the criteria for the Microsoft “Platform Test for ISV Solutions” program:  Windows Client, SQL Server 2005, Managed Code and Web Services + .NET Framework."

I plain English, this means Bambuco has passed tests for connecting and working with SQL Server and web services. There was no test relevant for the Groove-specific aspect, otherwise we'd have submitted it for that. The core code that makes up 90% of Bambuco is shared with our other products, which is a nice confidence booster.

"Testing was conducted independently by VeriTest, a testing service of Lionbridge Technologies."

Thursday, 22 November 2007

How do I add days to a date and save the results back to another field?

The Problem: I want to add a day to a field value, but when I do, I get weird values like "17 Jul 20061". Help!

The Cause: Your Groove script code is probably taking the text from a field and adding a '1' on the end of it. Script code is dumb and does't understand that "17 Jul 2006" is more than just a collection of letters and numbers.

The Solution: You need to use a bit of JScript (JavaScript) code to convert the text to a date, and do the arithmetic on the date.

How to:

  1. Open the forms Designer 
  2. If you cannot see a tab labelled "Form Scripts", check the "Show Advanced Design Features".
  3. Choose Add Script.
  4. Choose Choose New, give your script a name such as "field_changes.js".
  5. Copy the code below (the weird stuff between the two horizontal lines, dude!) into the script editor window.
  6. Change all occurrences of ContractDate to the date field you want to use as the starting date for your calculation. You can check what your fields are called by looking at the Fields -> Date Fields part of the Design Object Pane. The name isn't always the same as the label you gave the fields when you created them.
  7. Change the occurrence of ExpirationDate to the date field you want to calculate.
  8. Click Ok, then Save then Save To Groove.
  9. Test it. Put in a date in the first value - the second will change if all is good. If not, see the notes below.
  10. You're done!

When you change the starting date, the code should run and fill in the second date.


function ContractDate_OnChange() {
  try {
  var StartDateStr = GetHTMLFieldValue ("ContractDate");
  //alert ("StartDateStr:" + StartDateStr);
  var StartDateNum = GetApp().ParseDate(StartDateStr, GrooveIntlDateFormatStyle_Short);
  //alert ("StartDateNum: " + StartDateNum);
  var StartDate = new Date(StartDateNum);
  var NextDayOfMonth = StartDate.getDate() +1;
  //alert ("nextDayOfMonth:" + NextDayOfMonth);
  var NextDate = new Date(StartDate.setDate(NextDayOfMonth));
  var NextDateNum = NextDate.valueOf();
  var NextDateStr = GetApp().FormatDate(NextDateNum, GrooveIntlDateFormatStyle_Short);
  SetHTMLFieldValue ("ExpirationDate", NextDateStr);
  }
  catch (err) {
  GetApp().DisplayError("ContractDate_OnChange: " + err.description);
  }
}


How it works:

  1. Get the html field value we want to start from.
  2. Convert it to a number.
  3. Convert the number to a JScript Date object from the number.
  4. Calculate the next day of the month. Adding 1 to 31 works fine.
  5. Create a new JScript Date object by adding the next day of the month to the date we started with.
  6. Get its numeric value.
  7. Convert it to Text.
  8. Save it in our second field.
  9. You're done.

Notes:

  • Get Function Names right: Groove automatically links script code onto the forms objects, provided you make sure the function names match exactly what Groove is looking for. Here, our field is called ContractDate and we want to do our stuff when the value changes, so we need ContractDate_OnChange as our function name. The use of capital letters is important - ContractDate_Onchange (notice the little 'c'?) is not going to work.
  • JScript Dates are a pain! Working with dates in JScript is an unpleasant experience. Sorry, there's nothing I can do about that apart from point you to Microsoft's own documentation. See the link below.
  • Make sure you get the date formats right. On my form the dates are shown in the short date format, so I've used GrooveIntlDateFormatStyle_Short to make sure m script code works to the sam format. If you use a incompatible formats between the code and the form you'll get an error.
  • Turn on some messages. If you're having problems with the script giving an error, you can start to work out where and why by un-commenting the 'alert' messages. Remove the // characters and the script will start showing dialog boxes. You can work out how far through you are getting which will hopefully point you towards the answer.
  • Still Stuck? Drop me an email - mark.smith@infopatterns.net.

Other Links:

Microsofts documentaion on the JScript Date object. It really prefers you to be using Internet Explorer.

I'm running Groove 2007. How do I accept invites to old spaces?

The Problem: You are running Groove 2007 and you cannot accept invitations to workspaces created using Groove 3.1 or earlier.

The Solution: Choose Options -> Preferences from the main Launchbar menu, and clear the box highlighted in red in the image below.

groove2007acceptoldspaces