Archive

Archive for the ‘Development’ Category

SQL: Select … for XML

May 23rd, 2012 No comments

The Select … for XML can be useful.  Let say that you want to list out Job Order information, one job per line, and one of the field will be WC, and you want to show all WCs for the job, in the format like WC1, WC2, WC3, …  Here is the select statement will work the trick.

Select j.job, j.suffix, j.order_date, j.item, j.qty_released,

(Select jr.wc + ‘,  ‘  as ‘text()’ from jobroute jr where jr.job = j.job and jr.suffix = j.suffix

  for XML path(”)) as ‘WC’

from job j where j.status = ‘R’

Categories: Development, SQL Tags: ,

Infor Prepares to Roll out ‘Mongoose’ Development Platform

April 24th, 2012 No comments

This is coming out of PCWorld.  Looks pretty positive to our Syteline fellow.

Infor Prepares to Roll out ‘Mongoose’ Development Platform

Categories: Development Tags:

Syteline Financial Excel Add-in: How to reference unit codes with mixed cell references and hard-coded values

April 14th, 2012 No comments

When specifying unit codes in the Excel formulas, to use both a cell reference in addition to hard-coded values, you need to append the two with ‘&’.  For example, if unit code 1 value is in cell $A$1, and you don’t want to include * for each of the three remaining unit codes, the Unit Code parameter would look like: $A$1 & ",*,*,*".  In a SLGL formula, that would look like:

=SLGL(account, period, year, $A$1 & ",*,*,*")

Categories: Development Tags:

Get Only Date from DateTime

April 4th, 2012 No comments
SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))

There is also a few useful UDF(User Defined Function) in Syteline

ConvDate (@pInputDate  DateType, @pFormat   NVARCHAR(10))

Sample

SELECT ConvDate(GetDate(), ‘MM/DD/YYYY’)

Another useful one, DayEndOf

ALTER FUNCTION [dbo].[DayEndOf] (

  @Date DATETIME

) RETURNS DATETIME

AS

BEGIN

    –  This function takes the input date and extends the time portion forward

    — to the last possible moment of that day, just before midnight of the next day.

    — A null in yields a null out. It is useful for doing

    — high-range comparisons where only the day matters and offers an alternative to the

    — DATEDIFF built-in. The first 4 bytes of a datetime field are the date and

    — the second four the time.

   
    RETURN case when @Date = CONVERT(DATETIME, ‘9999-12-31 23:59:59.998’, 121) then @Date

       else dateadd(ms, -2, dbo.MidnightOf( dateadd(day, 1, @Date) ) )

       end

END

Categories: Development, SQL Tags:

Calling a Synchronous Event within a SP Transaction and Handling Failure

March 20th, 2012 No comments

First, determine the current site, after which you must name a configuration, by convention:

DECLARE @Site SiteType
SELECT @Site = site FROM parms

Then determine the current SessionId:

 

DECLARE @SessionId RowPointerType
SET @SessionId = dbo.SessionIdSp()

Finally, add the procedure code:

 

BEGIN TRANSACTION
UPDATE coitem
SET due_date = dbo.CalcDueDate(@Parm1, @Parm2)
WHERE coitem.co_num = @CoNum
AND coitem.co_line = @CoLine
AND coitem.co_release = @CoRelease
SET @MyEventParmId = NEWID()
EXEC InsertEventInputParameterSp @MyEventParmId, ‘CoNum’, @CoNum
EXEC InsertEventInputParameterSp @MyEventParmId, ‘CoLine’, @CoLine
EXEC InsertEventInputParameterSp @MyEventParmId, ‘CoRelease’, @CoRelease

DECLARE
@anyHandlersFailed [tinyint],
@result [nvarchar](4000),
@Infobar [nvarchar](4000)
EXEC @Severity = FireEventSp
@eventName = SetCoitemDueDate’,
@configName = ‘SyteLine’,
@sessionID = @SessionID,
@eventTrxId = null,
@eventParmId = @MyEventParmID OUTPUT,
@transactional = 0,
@anyHandlersFailed = @anyHandlersFailed output,
@result = @result output,
@Infobar = @infobar output
IF @Severity > 0
BEGIN
EXEC RaiseError @Infobar, @Severity
ROLLBACK TRANSACTION
END

COMMIT TRANSACTION

Categories: Development, SQL Tags: ,

Date Time for Multi-Site

February 9th, 2012 No comments

Something to remember, in programming in multiple site environment, if you have site that has differ time zone than the server time zone, remember to use GetSiteDate function, instead of directly GETDATE().  Below is code sample.

   SET @PrintDate = dbo.GetSiteDate(GETDATE())

Syteline Performance Tuning–Part 1

January 21st, 2012 No comments

 

1) Update Statistics

You should always run the below command nightly

Exec sp_updatestats

2) Rebuild Index for key tables

It is worth to rebuild index for key tables regularly, like once a week.

DBCC DBREINDEX (ledger)
GO
DBCC DBREINDEX (item)
GO
DBCC DBREINDEX (customer)
GO
DBCC DBREINDEX (matltran)
GO
DBCC DBREINDEX (journal)
GO
DBCC DBREINDEX (ledger_all)
GO
DBCC DBREINDEX (matltran_amt)
GO

3) Defragment Index

Below script will defragment any index with over 20% logical fragmentation.  This should set to run weekly.

/*Perform a ‘USE <database name>’ to select the database in which to run
the script.*/
— Declare variables
SET NOCOUNT ON
DECLARE @tablename VARCHAR (128)
DECLARE @execstr VARCHAR (255)
DECLARE @objectid INT
DECLARE @indexid INT
DECLARE @frag DECIMAL
DECLARE @maxfrag DECIMAL
— Decide on the maximum fragmentation to allow
SELECT @maxfrag = 20.0
— Declare cursor
DECLARE tables CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = ‘BASE TABLE’
— Create the table
CREATE TABLE #fraglist (
ObjectName CHAR (255),
ObjectId INT,
IndexName CHAR (255),
IndexId INT,
Lvl INT,
CountPages INT,
CountRows INT,
MinRecSize INT,
MaxRecSize INT,
AvgRecSize INT,
ForRecCount INT,
Extents INT,
ExtentSwitches INT,
AvgFreeBytes INT,
AvgPageDensity INT,
ScanDensity DECIMAL,
BestCount INT,
ActualCount INT,
LogicalFrag DECIMAL,
ExtentFrag DECIMAL)
— Open the cursor
OPEN tables
— Loop through all the tables in the database
FETCH NEXT
FROM tables
INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
— Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC (‘DBCC SHOWCONTIG (”’ + @tablename + ”’)
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS’)
FETCH NEXT
FROM tables
INTO @tablename
END
— Close and deallocate the cursor
CLOSE tables
DEALLOCATE tables
— Declare cursor for list of indexes to be defragged
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, ‘IndexDepth’) > 0
— Open the cursor
OPEN indexes
— loop through the indexes
FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @indexid, @frag
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ‘Executing DBCC INDEXDEFRAG (0, ‘ + RTRIM(@tablename) + ‘,
‘ + RTRIM(@indexid) + ‘) – fragmentation currently ‘
+ RTRIM(CONVERT(varchar(15),@frag)) + ‘%’
SELECT @execstr = ‘DBCC INDEXDEFRAG (0, ‘ + RTRIM(@objectid) + ‘,
‘ + RTRIM(@indexid) + ‘)’
EXEC (@execstr)
FETCH NEXT
FROM indexes
INTO @tablename, @objectid, @indexid, @frag
END
— Close and deallocate the cursor
CLOSE indexes
DEALLOCATE indexes
— Delete the temporary table
DROP TABLE #fraglist
GO

4) Other script that should be run regularly

  • SLServerRestartSp – This stored procedure runs whenever the database server is
    restarted (since no one is logged in at that time) and performs general cleanup.
  • PurgeNextKeySp – Run this stored procedure to clean up the NextKeys table.
    NextKey records are inserted, never updated to get concurrency. This stored
    procedure cleans out the extra rows. DO NOT run this utility while others are using the
    system. The utility will lock users out, but you should log everyone out of the system
    before running this utility.

5) Scripts that can be used to return information related to performance

  • sp_who and sp_who2 – The stored procedure sp_who shows what SPID is blocked;
    sp_who2 shows who is blocking.
  • sp_helpindex (table_name) – Gives index information on a table.
  • DBCC OPENTRAN – Determines whether an open transaction exists within the log.
  • DBCC INPUTBUFFER (SPID) – Displays the last statement sent from a client to SQL
    Server.
  • dbcc showcontig (table_name) – This would show fragmentation information for a table.

Problem caused by changing slservice password

November 22nd, 2011 No comments

 

During Syteline installation, you provided a domain account (normally it would call something like SLService, and belongs to domain admin group), to install all the Syteline service.  If later on, you somehow change the password for this account, you would have problem access to Syteline.  Error message likes below would popup. 

It may also happens when user preview a report, below “access denied” message show up

Here are the steps for fixing this,

First, in Utility server, go into IIS, check into IDORequestService

Open the Authentication windows, right click on Anonymous Authentication and select “Edit”.  In “Edit Anonymous Authentication Credentials” window, click the “Set” button, then provide userid/password there.

Repeat the steps for SLClientDeploy, InforInbox, InboundQueue, fsdatacollection。

Now, you are ready to test it out from client side.

Obtaining Username in form script

October 24th, 2011 5 comments

In syteline 7 it was SessionManager.BaseUserName.
In Syteline 8

  • Create form component ‘UserEdit’ and bind it to variable ‘User’ with initial value ‘USERNAME()’
  • Get the value on form script by ‘ThisForm.Variables(“User”).Value’
    This will return the UserID who login to Syteline.
  • Use System.Environment.UserName to get the UserID login to Windows.

Here is a sample screen shot

ScreenHunter_04 Mar. 21 10.29

Easy way to link a show only field to Form

October 15th, 2011 No comments

Let say you want to show item material status in Item Availability Form, you may just create a new edit field in form, then bind the form component to

COLLECTION(SL.SLItems(PROPERTY(Stat) FILTER(Item = FP(Item)))) .

Please note that if you want to do this in grid column, since the value is not in collection, so the grid column would be blank initially.  Only when you click on a row, the column value would show.