Tuesday, November 21, 2017

SQL code to check for open GL period in Dynamics GP

In Dynamics GP periods can and should be closed to prevent users from posting data where they should not.  To determine if the period is closed use the following code in SQL Server:


DECLARE @I_sSeries SMALLINT,
        @I_cOrigin CHAR(50),
        @I_dDate DATETIME,
        @I_dUserDate DATETIME,
        @O_sPeriodID SMALLINT,    -- Period ID
        @O_tClosed TINYINT,  -- 1 if period is closed
        @O_sYear SMALLINT, -- fiscal year
        @O_iOUTErr INT,   -- 0=no errors; 2=date not in a fiscal year; 3=unknown
        @O_iErrorState INT;

-- Financial=2, PM=4, Sales=3, IV=5, PR=6
SET @I_sSeries = 2;
-- SELECT DISTINCT odesctn FROM sy40100 ORDER BY odesctn
SET @I_cOrigin = 'General Entry';
-- date to check if period is closed
SET @I_dDate = '11/1/17';
SET @I_dUserDate = CAST(GETDATE() AS DATE);

EXEC Glcalculateglperiod @I_sSeries, @I_cOrigin, @I_dDate, @I_dUserDate,
 @O_sPeriodID OUTPUT, @O_tClosed OUTPUT, @O_sYear OUTPUT, @O_iOUTErr OUTPUT, @O_iErrorState OUTPUT;
SELECT @O_sPeriodID, @O_tClosed, @O_sYear, @O_iOUTErr, @O_iErrorState
PRINT CASE WHEN @O_tClosed = 1
THEN 'Period is Closed'
ELSE 'Period is Open' END;


Thursday, November 16, 2017

Smartlist Builder misbehaving on Go To

Using Dex in Dynamics GP 2015R2 I created a custom table and have a Smartlist created for this data.  There is an unique ID field for each record in the table and an index on that field.

When I created the Smartlist for this I wanted a GoTo that would open the inquiry window I created in Dex for this table.

When the form opened it sometimes displayed the right record, and sometimes did not.

I sorted for the form by a different column and found that it was returning the first in the sequence by that column.

I realized that it was likely the key of the Smartlist table was probably defined incorrectly.  When I adjusted that I received the correct result.