The Easy Way to Refresh Your Dynamics GP Test Company – Part Three
In our last sessions, we created the SQL backup job and then the Restore step. In this session, we will add the test company fix-up script to our job.
1) Go to the server where SQL Server is installed, and your Dynamics GP databases are located.
2) Launch SQL Server Management Studio and log in as SA or a user with System admin rights.
3) Expand SQL Server Agent and then Jobs. Look for the job you used in our last session. In this case, it is: “Back Up Database – TWO and Restore To Test”. Double click the job to open it.
4) Select Steps from the left pane shown below.
- Then New at the bottom of the right pane
- On the “New Job Step” window that opens select “General” on the left pane
- Name the step under “Step Name” in the right window. In this case I called it “”Run Test Company Fix Script”
- Change the Database to TEST in this case. You may have a different name for your test database for Dynamics GP
- Paste this script below into the Command window:
- If you are having issues with this script, you can obtain it here.
if exists (select 1 from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'SY00100') begin declare @Statement varchar(850) select @Statement = 'declare @cStatement varchar(255) declare G_cursor CURSOR for select case when UPPER(a.COLUMN_NAME) in (''COMPANYID'',''CMPANYID'') then ''update ''+a.TABLE_NAME+'' set ''+a.COLUMN_NAME+'' = ''+ cast(b.CMPANYID as char(3)) else ''update ''+a.TABLE_NAME+'' set ''+a.COLUMN_NAME+'' = ''''''+ db_name()+'''''''' end from INFORMATION_SCHEMA.COLUMNS a, '+rtrim(DBNAME)+'.dbo.SY01500 b where UPPER(a.COLUMN_NAME) in (''COMPANYID'',''CMPANYID'',''INTERID'',''DB_NAME'',''DBNAME'') and b.INTERID = db_name() and COLUMN_DEFAULT is not null and rtrim(a.TABLE_NAME)+''-''+rtrim(a.COLUMN_NAME) <> ''SY00100-DBNAME'' order by a.TABLE_NAME set nocount on OPEN G_cursor FETCH NEXT FROM G_cursor INTO @cStatement WHILE (@@FETCH_STATUS <> -1) begin exec (@cStatement) FETCH NEXT FROM G_cursor INTO @cStatement end close G_cursor DEALLOCATE G_cursor set nocount off' from SY00100 exec (@Statement) end else begin declare @cStatement varchar(255) declare G_cursor CURSOR for select case when UPPER(a.COLUMN_NAME) in ('COMPANYID','CMPANYID') then 'update '+a.TABLE_NAME+' set '+a.COLUMN_NAME+' = '+ cast(b.CMPANYID as char(3)) else 'update '+a.TABLE_NAME+' set '+a.COLUMN_NAME+' = '''+ db_name()+'''' end from INFORMATION_SCHEMA.COLUMNS a, DYNAMICS.dbo.SY01500 b where UPPER(a.COLUMN_NAME) in ('COMPANYID','CMPANYID','INTERID','DB_NAME','DBNAME') and b.INTERID = db_name() and COLUMN_DEFAULT is not null order by a.TABLE_NAME set nocount on OPEN G_cursor FETCH NEXT FROM G_cursor INTO @cStatement WHILE (@@FETCH_STATUS <> -1) begin exec (@cStatement) FETCH NEXT FROM G_cursor INTO @cStatement end close G_cursor DEALLOCATE G_cursor set nocount off end
5) Now from the left pane, select Advanced
- From the right pane select “On success action” and pick “Quit the Job Reporting Success”
6) Now click OK and OK again to save the job.
In our next session, we will cover running and troubleshooting the job we just created. For any further questions, contact Stoneridge Software.