GP Scripts

Posted on

Assign All Items to a given Vendor
 —————————————————————-

— Assign All Items to a all Vendors

— Code by Venugopal G A

— mail me for any queries venuasg@gmail.com / venuasg@yahoo.com
—————————————————————-

DECLARE @VENDORID VARCHAR(30)

DECLARE @ITEM VARCHAR(100)

DECLARE @ITEMDESC VARCHAR(100)

DECLARE VENDOR CURSOR FOR

SELECT VENDORID FROM PM00200
OPEN VENDOR

FETCH NEXT FROM VENDOR INTO @VENDORID

WHILE (@@fetch_status <> -1)

BEGIN

DECLARE ITEMMASTER CURSOR FOR

SELECT ITEMNMBR, ITEMDESC FROM IV00101

OPEN ITEMMASTER

FETCH NEXT FROM ITEMMASTER INTO @ITEM, @ITEMDESC

WHILE (@@fetch_status <> -1)

BEGIN

INSERT INTO [IV00103] ([ITEMNMBR],[VENDORID],[ITMVNDTY],[VNDITNUM],[VNDITDSC])
VALUES(@ITEM,@VENDORID,1,@ITEM,@ITEMDESC)

FETCH NEXT FROM ITEMMASTER INTO @ITEM, @ITEMDESC

END

DEALLOCATE ITEMMASTER

FETCH NEXT FROM VENDOR INTO @VENDORID

END

DEALLOCATE VENDOR

SQL Script to find missing or deleted Journal No in Microsoft GP

Posted on

Script
 
————————————————————————-
— Find Missing or deleted Journal Entry No in Microsoft GP
— Code by Venugopal G A
— mail me if you need query for other type of transactions or for any
— queries venuasg@gmail.com
————————————————————————-
If Object_Id(‘tempdb..#tempJV’) is Not Null
Drop table #tempJV

create table #tempJV
(
JVno int,
MJV int identity(1,1)
)

insert into #tempJV (JVno)
(select distinct JRNENTRY from GL20000 )

select wg.MJV as id_is_missing
from #tempJV wg
left join #tempJV ti on wg.MJV = ti.JVno
where ti.JVno is null
order by wg.MJV


SQL Script to Compare Bank Subledger balance to corresponding GL account balance

Posted on

Script
 
—————————————————————————-
— Compare Bank Subledger balance to corresponding GL account balance in GP.
— Code by Venugopal G A
— mail me for any queries venuasg@gmail.com
—————————————————————————-
DECLARE @CHECKBOOKID VARCHAR(30)
SET @CHECKBOOKID = ‘FIRST BANK’ — CHANGE THIS TO YOUR CHECKBOOK ID
–Set Bank Type and get Bank Balance
Select ‘Bank’ as SubType, CURRBLNC as SubBal, 0 as GLBal
Into #SubtoGLCompare From CM00100 Where Chekbkid=@CHECKBOOKID
/*Get the GL total for this Account. Change the account below or optionally add additional
actnumbr parameters to tighten or broaden the account*/
INSERT #SubtoGLCompare (SubType,SubBal,GLBAL)
SELECT ‘Bank’ as SubType, 0 as SubBal, SUM(Perdblnc) AS GLBal
FROM GL11110 WHERE actnumbr_2 = ‘1100’ — Change this
Select SubType, sum(Subbal) as SubBal, Sum(GLBal) as GLBAL, sum(SubBal)-Sum(GLBAL) as Difference,
‘Difference is Subledger minus GL.’ as Instructions
from #SubtoGLCompare
Group by SubType
Drop Table #SubtoGLCompare


SQL Script to assign all items to all sites in Microsoft GP

Posted on

Assign All Items to ALL Sites
 
——————————————————–
— Assign All Items to ALL Sites
— Code by Venugopal G A
— Below script will assign all the available inventory item
— to all available sites if they are not assigned already.
— mail me for any queries venuasg@gmail.com
——————————————————–
DECLARE @ITEM varchar(100)
DECLARE @LOCATION varchar(100)
DECLARE @ITEMAlreadyExist int

DECLARE ITEMMASTER CURSOR FOR
SELECT ITEMNMBR FROM IV00101
OPEN ITEMMASTER
FETCH NEXT FROM ITEMMASTER INTO @ITEM
WHILE (@@fetch_status -1)
BEGIN
DECLARE SITE CURSOR FOR
SELECT LOCNCODE FROM IV40700
OPEN SITE
FETCH NEXT FROM SITE INTO @LOCATION
WHILE (@@fetch_status -1)
BEGIN
SELECT @ITEMAlreadyExist = isnull(count(*), 0) FROM IV00102
where ITEMNMBR = @ITEM and LOCNCODE = @LOCATION
if @ITEMAlreadyExist = 0
BEGIN
INSERT INTO IV00102 VALUES(@ITEM,@LOCATION,”,2,”,0,0,0,0
,’01/01/1900′,”,’01/01/1900′,0,0,0,0,0,0,0,0,0,0,0,0
,’01/01/1900′,’01/01/1900′,’01/01/1900′,’01/01/1900′,0,”
,”,”,1,0,0,1,0,0,1,2,0,0,0,0,0,0,0,1,0,0,0,3,0,0,0,”
,”,”,”,”,”,”,”,1,1,”,1,1,0,1,1,1,0,0,0,0,0)
END
FETCH NEXT FROM SITE INTO @LOCATION
END
DEALLOCATE SITE
FETCH NEXT FROM ITEMMASTER INTO @ITEM
END
DEALLOCATE ITEMMASTER


SQL Script to assign all Items to a given Vendors

Posted on

Assign All Items to a given Vendor
 ——————————————————–
— Assign All Items to a given Vendor
— Code by Venugopal G A
— mail me for any queries venuasg@gmail.com
— Change the vendor variable to your vendorid
——————————————————–
DECLARE @VENDORID VARCHAR(15)
DECLARE @ITEM VARCHAR(100)
DECLARE @ITEMDESC VARCHAR(100)
SET @VENDORID = ‘ACETRAVE0001’

DECLARE ITEMMASTER CURSOR FOR
SELECT ITEMNMBR, ITEMDESC FROM IV00101
OPEN ITEMMASTER
FETCH NEXT FROM ITEMMASTER INTO @ITEM, @ITEMDESC
WHILE (@@fetch_status -1)
BEGIN
INSERT INTO [IV00103] ([ITEMNMBR],[VENDORID],[ITMVNDTY],[VNDITNUM],[VNDITDSC])
VALUES(@ITEM,@VENDORID,1,@ITEM,@ITEMDESC)

FETCH NEXT FROM ITEMMASTER INTO @ITEM, @ITEMDESC
END
DEALLOCATE ITEMMASTER

Items Having Current Cost and No Movement

Posted on


At time you want to audit the inventory items which are having Current Cost and no Movement (these items normally exist in GP during the migration process or upgrade process from the old system), below query gives you the list of such items in GP. The listed items are safe to delete from the system if they are not really required (delete at you own risk).

SELECT LTRIM(RTRIM(IV00101.ITEMNMBR)) as ITEMNMBR, IV00101.STNDCOST, IV00101.CURRCOST, IV00102.QTYONHND
FROM IV00101 INNER JOIN IV00102 ON IV00101.ITEMNMBR = IV00102.ITEMNMBR
WHERE    (IV00102.RCRDTYPE = 1) AND (IV00102.QTYONHND = 0) AND (IV00101.CURRCOST > 0)
    AND IV00101.ITEMNMBR NOT IN (select distinct(itemnmbr) from IV30300)
Come back for more tips ….. J

AA Transaction Error – Primary Key Voilation

Posted on


There are quite a few errors comes in AA which are not highlighted in the knowledge base articles.
Transaction dimensions can’t able to be saved. System had thrown you the following message

  • ‘Primary key violation error on table AAG00600. Cannot insert duplicate records on table’ along with that message there was another saying
  • ‘The stored proc aagCreateTree returned the following results. DBMS: 2627, Great Plains: 0’.

Resolution
This problem is due to the aaTreeID which is the primary key violation of AAG00600. In order to rectify it follow the process below.
Run all the below steps in SQL Server Query Analyser
Step 1:- select * from dynamics..sy01500 (used to know the company id)
Step2:- select * from dynamics..aag00102 where aatableid = 600 (‘600’ is the source aa table ID for which the corresponding aaRowID mentioned is the last rowid inserted in AAG00600 for the corresponding is company ID)
Step3:- select * from two..aag00600 (look for the aaTree ID were the last record inserted is holding the same ID as that of the aaRowID in aag00102 table)

If the rowid and the tree id is not same for the corresponding company then you will be getting the above message which will not allow you to save the new transaction dimension for that company. So use the following code to make the rowid as same as that of the aatree id in AAG00600.

Step4:- update dynamics..aag00102 set aarowid = 14 where dex_row_id = 4

Find Missing / Deleted Journal Entry in Microsoft GP

Posted on


When your company auditor ask for all the missing or deleted Journal entry, it’s not a big task now you can get it in minutes by running the script below in your SQL query analyser.
If Object_Id(‘tempdb..#tempJV’) is Not Null
Drop table #tempJV
create table #tempJV
(JVno int,MJV int identity(1,1))

insert into #tempJV (JVno)
(
select distinct JRNENTRY from GL20000 )

select wg.MJV as id_is_missing
from #tempJV wg left join #tempJV ti on wg.MJV = ti.JVno
where ti.JVno is null order by wg.MJV


Keep visiting this site for more Dynamics Tips… J