peas⋅ant /ˈpɛzənt/ [pez-uhnt] –noun 1. a member of a class... (snip) 2. a coarse, unsophisticated, boorish, uneducated person of little financial means (the author, not the reader).
Tuesday, October 6, 2009
JScript birth date madness
The issue is the use of ISO8601 format of YYYY-MM-DD versus the entry format of MM-DD-YYYY. The solution is to parse the string before doing the math. A complete "age" functions is as follows:
if (eventObj.IsUnDoRedo)
{
return;
}
//==============================================
//= On date of birth changed calculate age in years and set age field
//==============================================
var DOB = XDocument.DOM.selectSingleNode("my:myFields/my:DateOfBirth");
if ((DOB != null) && (DOB.text != ""))
{
var myStringList = DOB.text.split('-');
var DOBText = myStringList[1]+'/'+myStringList[2]+'/'+myStringList[0];
var dt1 = new Date();
var dt2 = new Date(DOBText);
var years = dt1.getFullYear() - dt2.getFullYear();
// Check to see if it's before or after this years birthday
dt2.setYear(dt1.getFullYear());
if (dt1 <>
{
years--;
}
SetField("Age",years);
}
}
Friday, May 1, 2009
Picking a single node from an eventObj
The object orientation of the JSCript code makes that a snap.
The button that was pressed, in particular, is the eventObj passed to the event handler. The "Source" Property is a reference to the other items in the row.
If we reference the form as seen, then the particular participant bound to the button in the row pressed is referenced as eventObj.Source.selectSingleNode("my:Participant").text
One important item of note, while doing the walkthru we used the path starting at the root... i.e. "//my:Participant". Since the button is already below the parent you need to reference it as "my:Participant" or at best, you'll always get the first child node.
Monday, February 23, 2009
Clearing some underbrush
Thursday, February 12, 2009
Next Up
So here is a very early list of what if's
- Income impact of program income by percentage
- Line item, across the board or by entity tree percentage changes
- Reducing staff work days
- Ratio tools for employment related costs
But I do need some basis for better study...
Friday, January 30, 2009
Forms within Forms
Launching a form is a point and click exercise, doing so while exposing the other forms fields requires a bit of code, but as it turns out, not much.
var newForm = Application.XDocuments.NewFromSolution(http://sharepoint/sites/it/area54/Sample Face Sheets/Forms/template.xsn);
var participant = newForm.DOM.selectSingleNode("my:FaceSheet/my:Client_Name");
myField = XDocument.DOM.selectSingleNode("my:myFields/my:Test");
participant.text = myField.text;
The first line launches the form, you’ll need the path to the form template, but that’s it. Your newForm variable then contains XDocument for the form just launched, in this case the face sheet. Now you can grab a field value from the parent form and copy it into the new form.
Wednesday, January 28, 2009
Dash Phone as a laptop Internet connection
While our default configuration connects directly with our exchange server, limiting the ActiveSync to a workstation’s utility, there is one really nifty feature I tried out on the new phone last night.
You can use the phone as a cellular modem to connect your laptop to the internet while on the road.
To do so first install the ActiveSync software that comes with the phone. If you have already set-up your access to exchange it will keep that configuration and by default will only load your Internet favorites to the phone on synch, otherwise it changes nothing. In our case we really don’t want the synch, just the drivers it installs, which is why we never bothered with doing this on the Q Phones.
Once installed, close the program, and connect the phone to the laptop using the USB cable provided.
From now on you’ll be able to use the phone to connect to the internet wherever you have a signal for your phone. Just connect the cable, and then select “Start”, “Accessories”, “Internet Sharing” on the phone. There will be three fields on the phone, “Status”, “PC Connection”, and “Network Connection”. Leave the Network Connection on T-Mobile Data, make sure the PC Connection is still USB, and then use the left button on the phone to change the status from disconnected to connected.
The speed is not blazing, functionally its speed is roughly equal to a 28.8 modem, but it operates anywhere. That is worth it…
Monday, January 26, 2009
InfoPath Date Math Shuffle
But it can be done in 2003 with a fairly short VB script. Problem was I started out trying to write it as a Jscript and kept running into a lack of functionality… So anyway here is how to do the InfoPath 2003 Date Math Shuffle in all it’s glory.
Step One: Set the form to use VB Script in place of Jscript. This can only be done at the start, before you write any code for the form. Select Tools, then form options. This will open the form options dialog box, allowing you to select the Advanced Tab, where you can set the programming language to Visual Basic Script (VBScript as shown above).
To test it I added two date fields and a text field to a blank form.
Once there we can open our editor so we can add the code by grabbing the properties of the second date picker, select the onAfterChange event and click on the Edit button.
This will launch the Microsoft script editor for the proper event.
Of course after we’re done we should go back and add a call to the first date to the second date’s event in case the form’s user changes the first date after the second… heh.
But for now let’s just add the code. Thank goodness that the VB editor seems to have all the functionality that the Jscript lacked. At one point I was even considering a web-service call, but as it turns out that this VB script can handle this in a flash and without any of the nasty delays inherent in a web-service.
So, Step two is to write the code for the event. First we need to leave the premade code alone, it's only there in the event an "If eventObj.IsUnDoReDo" argument is present, and we don't care.
Below is the code, with further descriptions commented in the event you want to cut and paste it in as is...
‘==========
‘ date_from follows the XDocument path to get access to the forms SecondDate Field
‘ date_to is the same for the first date field
‘ dt1Val is a variable where we will load the value of the date_from field
‘dt2Val is a variable where we will load the value of the date_to field
‘daysElapsed is a variable where the difference is calculated
‘==========
Dim date_from
Dim date_to
Dim dt1Val
Dim dt2Val
Dim DaysElapsed
‘=====
‘ Now we set the date_from and date_to so we can read the fields
‘=====
Set date_from = XDocument.DOM.selectSingleNode("/my:myFields/my:SecondDate")
Set date_to = XDocument.DOM.selectSingleNode("/my:myFields/my:FirstDate")
‘======
‘ Then we test the fields to see if we have dates in both fields, if so then we calculate the difference and put
‘ it into the display field on the form, otherwise we make the display field blank
‘======
If (date_from.Text <> "") and (date_to.Text <> "") Then
dt1Val = CDate(date_from.Text)
dt2Val = CDate(date_to.Text)
daysElapsed = DateDiff("d",dt2Val,dt1Val)
XDocument.DOM.selectSingleNode("/my:myFields/my:Difference").Text = daysElapsed
else
XDocument.DOM.selectSingleNode("/my:myFields/my:Difference").Text = ""
End If
All that is left is to call this function when the first date changes by creating it’s event just as you did the second date fields and copying the function call, in this case:
msoxd_my_SecondDate_OnAfterChange(eventObj)
Not too shabby, but having Microsoft add the DateDiff function to InfoPath, as I believe they did in 2007 would have saved my people a lot of trouble.
