Buttons on forms?

Long time ago we needed to have a button on HRNET screen. If you work with HRNET, you know, there are no buttons available on the screens.

Today almost no need for buttons, but I’ll tell you how the buttons can be done.

  • First, drag a text-field to the form canvas. Do not associate thie field with any data.
  • Call this text-field, say, “newButton
  • In Custom Script write this:
    var newButton = document.getElementById("NewButton"); 
    
    newButton.innerHTML = '';
    
    
    
    
    
    function sayHello(){
    
    alert("Hello!!");  
    
    }
    
    
    
  • Load this screen in the front-end. Enjoy the button.

I hope you don’t need to be told what to do with buttons.. -))

Posted in Uncategorized | Tagged , , , | 4 Comments

Function in computed field in temp table

It is not easy to set up function on computed field in temp table. I spent the whole day trying to resolve this… and here is the answer:

use hrnetdev

declare @functions nvarchar(4000)

set @functions = '

use [tempdb] 




IF EXISTS( SELECT 1 FROM information_schema.routines WHERE routine_name = ''distance'')

	DROP FUNCTION dbo.distance;

SET ANSI_NULLS ON;

SET QUOTED_IDENTIFIER ON;



exec(''CREATE FUNCTION dbo.distance( @x1 int, @y1 int, @x2 int, @y2 int)

RETURNS decimal(10,3) AS

BEGIN

	DECLARE @distance bigint

	set @x1 = isnull(@x1, 0)

	set @y1 = isnull(@y1, 0)

	set @x2 = isnull(@x2, 0)

	set @y2 = isnull(@y2, 0)



	set @distance = sqrt(  (@x1-@x2)*(@x1-@x2) + (@y1-@y2)*(@y1-@y2) )



	RETURN @distance

END'')


'

exec(@functions)



select tempdb.dbo.distance(0,5,5,5)
Posted in Uncategorized | Tagged , , | Leave a comment

Parse Hrnet Date

Simple snippet for Custom Scripts: convert form HRNET date string into JavaScript format

/**

 * Parce from string representind date in format "dd/mm/yyyy" into JavaScript Date format

 */

function parseDate(strDate){

	var array = strDate.split("/");

	return new Date(array[2], array[1]-1, array[0], 0,0,0);

}


Posted in Uncategorized | Tagged , , , , | Leave a comment

Screen Validation

Many times I need to validate entries on the screen via JavaScript (or Custom Script, in terms of HR.Net).
For about a year I struggled with validation via overloading function “Page_ClientValidate“. But when you overload this function, you can’t run original validation that HR.Net prepared for you, so if in the table you have regular expression validation, it is not executed. But when you try to save incorrect data (according to the regexp) this does not show any message and doesn’t save as well.. which is very frustrating to the user.
Today I’ve discovered new way of calling validation function with using original HR.Net procedure:

var org_Page_ClientValidate = window.Page_ClientValidate;

window.Page_ClientValidate = function(){
  var ErrMsg ='';
  var validate = true;
// your custom validation goes here
  
	if (!validate){
		alert(ErrMsg);
		return false
	}

	return org_Page_ClientValidate();
}	
Posted in Uncategorized | Tagged , , , , , | 3 Comments

Drupal and HRNET

Would anybody be interested in module for Drupal that interacts with HRNET?

Currently I’m working on one of the subsystems and building a module for Drupal to read/write data from HRNET, and I can see how this can be developed into a general purpose php library and module.
Please leave a comment here, or drop me a line: mail [ at ] amvcomp.co.uk

Posted in Uncategorized | Leave a comment

Table definitions

For those of you wanting to know where HRNET stores meta information about tables and table-fields:
look into oc_fileddefs for field definitions – type of data, validation, etc.
For field captions and descriptions go to oc_filedlanguages.

Posted in Uncategorized | Tagged , , | Leave a comment

PHP Error: unable to get Memo fields from HRNET

When I was doing select statement from HRNET database, one of the problems was that I got error looking like this:
warning: mssql_query() [function.mssql-query]: message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier
This is due to mssql driver not supporting table fields of type ntext. To avoid this change your sql request from

select ntextfield from table

to

select CAST(ntextfield AS TEXT) as ntextfield from table

p.s. Update for this issue:
Instead of using mssql library in php, use sqlsrv – less problems and resolves other issues with mssql (as limited length of the table-name or field-name)

Posted in Uncategorized | Tagged , , | Leave a comment

Regexp to validate MS SQL uniqueidentifier

I’m working on PHP project that interacts with HRNET and at some point I need to validate if given string is valid mssql guid. For this I use php regular expression:
^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$

Posted in Uncategorized | Tagged , , | 2 Comments

More JavaScript snippets

To open help screen:

ShowHelp();

Returns true or false depending if the form validates or not.

IsPageValid();

To switch screen into attached documents, print this

setTimeout("ShowAttachedDocs()",0);

if you print only ShowAttachedDocs() – this will give you an error when you open a screen.
Probably some things need time to load up.

Posted in Uncategorized | Tagged , , , | 1 Comment

Find End of a Day for Given Date

Determines the last second for the day for the given date

CREATE FUNCTION [dbo].[EndOfDay]

(

	@DATE DATETIME

)

RETURNS DATETIME

AS

BEGIN



	RETURN DATEADD(s,-1,DATEADD(d, DATEDIFF(d,0,@DATE)+1,0))



END




Posted in Uncategorized | Tagged , , , | Leave a comment