Get local time based on field

I had an interesting request from one of our users as we update our address book. Is there a way to query a website via Notes and return a value back into a Notes ‘computed for display’ field?

I’d like to have our address book read the city and state fields, go out to the Internet and pull down data to present in another field.

For instance, if someone were to open the Notes document of our New York office, I’d like to display the local time, maybe weather, etc. I’m sure I can find some websites to query this info from, but I’m not sure how to start from the actual Notes code side.

This application is for Lotus Notes clients only, so the code will need to work inside a Notes document.

Any guidance would be appreciated.

Thanks.

Subject: Get local time based on field

Alex’s solution is very good for anyone with a grasp on Java.

If the client is Windows-based, you may want to also check out the NotesFTP script library which resides in the Sandbox (http://www-10.lotus.com/ldd/sandbox.nsf/0/9e752a60b6f902c7852568ef006b4ad1?OpenDocument).

While this solution is win32 only, it is very easy to use.

Just another option.

T.

Subject: Thanks Terry

Always good to get additional feedback. It’s great having all these options at your fingertips! :wink:

Alex

Subject: Get local time based on field

You could write this using Java and the Domino supported Java classes.

We have a Java app we include in our applications for checking for updates. The applications are distributed to customers who, from their Notes client, select an option from the actions menu to check for updates to the application.

A java agent runs on the Notes client, connects to a webpage on our website and parses the retrieved HTML code to get the value(s) of the fields we need to determine if an update is available.

Alex


Here’s a sample of the Java code to get you started…

public void NotesMain() {	

	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();

		Database db = agentContext.getCurrentDatabase();

		

		// Product update URL

		String productURL = "<put url address here>";



		// Connect to the URL and pull down the page

		URL applicationURL = new URL(productURL);

		BufferedReader bin = new BufferedReader (  new InputStreamReader(applicationURL.openStream( ) )); 

		String line; 

		StringBuffer sb = new StringBuffer();

	

		while ( (line = bin.readLine( )) != null ) { 

			sb.append(line);

		}



		String responseString = sb.toString();



		// Create a document in this database and call ComputeWithForm to parse the

		// received data.

		Document updateDoc = db.createDocument();

		updateDoc.replaceItemValue ("Form", "UpdateForm");

		updateDoc.replaceItemValue ("ApplicationPage", responseString);

		updateDoc.computeWithForm( true , false);

		updateDoc.save( true, true );



		// Check the NewUpdateFound field to see if a new version was detected.

		String newVersionFound = updateDoc.getItemValueString("NewUpdateFound");

.

.

.

.

.

And then we have an editable field on the form we created which does the actual parsing (processing each Input item & value to get what we need) and its Input Translation formula is:

TextToParse:=@LowerCase(ApplicationPage);

ItemString:=“”;

ItemName:=“”;

ItemValue:=“”;

@While(

@Contains(TextToParse; "input name=\"");

	@Do(

		@Set("ItemString"; @Right(TextToParse; "input name=\""));

		@If(

			@Contains(ItemString; ">");

				@Set("ItemString"; @Left(ItemString; ">"));

			""

		);

		@Set("TextToParse"; @Right(TextToParse; ItemString));

		@If(

			@Contains(ItemString; "\"");

				@Set("ItemName"; @Left(ItemString; "\""));

			@Set("ItemName"; "")

		);

		@If(

			@Contains(ItemString; "value=\"");

				@Set("ItemValue"; @Right(ItemString; "value=\""));

			@Set("ItemValue"; "")

		);

		@If(

			@Contains(ItemValue; "\"");

				@Set("ItemValue"; @Left(ItemValue; "\""));

			""

		);

		@ReplaceSubstring(ItemName; " "; "_");

		@If(

			@Trim(ItemName) != "";

				@SetField(ItemName; ItemValue);

			""

		);

		@If(

			@Trim(ItemName) = "version";

				@If(

					@Contains(ItemValue; ".");

						@Do(

							@SetField("MajorVersionNew"; @TextToNumber(@Left(ItemValue; ".")));

							@SetField("MinorVersionNew"; @TextToNumber(@Right(ItemValue; ".")))

						);

					@Do(

							@SetField("MajorVersionNew"; @TextToNumber(ItemValue));

							@SetField("MinorVersionNew"; 0)

					)

				);

			""

		)

	)

);

NewMajorVersion:=

@If(

@Trim(@Text(MajorVersionNew)) = "";

	MajorVersionCurrent;

MajorVersionNew

);

NewMinorVersion:=

@If(

@Trim(@Text(MinorVersionNew)) = "";

	MinorVersionCurrent;

MinorVersionNew

);

NewVersionCheck:=(NewMajorVersion*100) + NewMinorVersion;

CurrentVersionCheck:=(MajorVersionCurrent*100) + MinorVersionCurrent;

FIELD NewUpdateFound:=

@If(

NewVersionCheck > CurrentVersionCheck;

	"A newer version (release " + @Trim(@Text(MajorVersionNew)) + "." + @Trim(@Text(MinorVersionNew)) + ") of this application was found.  You are currently using release " + @Trim(@Text(MajorVersionCurrent)) + "." + @Trim(@Text(MinorVersionCurrent)) + ".  It is recommended you download the latest release to benefit from new features, fixes and enhancements";

""

);