Top Categories:
Dynamics GP
ClassicPress

Find text in any SQL object

Microsoft SQL ServerI needed to find custom triggers or views which referenced a certain table and although I thought I had a script which would find text in a SQL object like a trigger, view or stored procedure, I couldn’t find one when I searched my site the other day.

It only took me a few minutes to write one; the first highlighted text is the text to search for and the second a limitation on the name of the SQL objects to check.

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DECLARE @Search varchar(255) SET @Search='PM00200' SELECT DISTINCT ['SQL Objects'].name AS Object_Name ,['SQL Objects'].type_desc FROM sys.sql_modules AS ['SQL Modules'] INNER JOIN sys.objects AS ['SQL Objects'] ON ['SQL Objects'].object_id=['SQL Modules'].object_id WHERE ['SQL Objects'].name LIKE 'u%_AZRCRV_%' AND ['SQL Modules'].definition LIKE '%'+@Search+'%' ORDER BY ['SQL Objects'].name ,['SQL Objects'].type_desc

SQL script to create macro to delete items in Microsoft Dynamics GP

Microsoft Dynamics GPI’ve been doing some work with SmartConnect for a client recently where one of the integrations was creating new items. As the project progressed, some of the items which had been imported needed to be replaced with different item numbers. To ensure we didn;t cause problems, I didn’t want to delete items through SQL directly, due to the number and variety of tables involved, so needed to come up with a way of generating the macro.

Macros are useful ways of repeating an action, such as deleting items, but any variation to the data and the macro will fall over. One variation was that some items had posted transactions against them so I needed to avoid these transactions.

I created the below script to create the macro for me, with SSMS set to output to text, and built in joins and checks on all of the relevant tables in Purchase Order Processing, Inventory and Sales Order Processing which may have contained data. The script is probably a little overkill on the checks it does, but I wanted to make sure it caught as much as possible.

Once the script has been run, you can copy the macro text into a file and play the macro to delete the items (if you have a lot of items, you can play the macro fast).

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
SELECT '# DEXVERSION=14.00.0085.000 2 2 CheckActiveWin dictionary ''default'' form ''IV_Item_Maintenance'' window ''IV_Item_Maintenance'' TypeTo field ''Item Number'' , ''' + CAST(RTRIM(['Item Master'].ITEMNMBR) AS VARCHAR(50)) + ''' MoveTo field Inactive # ''FALSE'' CommandExec dictionary ''default'' form ''IV_Item_Maintenance'' command ''Delete Button_w_IV_Item_Maintenance_f_IV_Item_Maintenance'' # Are you sure you want to delete this record? NewActiveWin dictionary ''default'' form DiaLog window DiaLog ClickHit field OK NewActiveWin dictionary ''default'' form ''IV_Item_Maintenance'' window ''IV_Item_Maintenance'' ' FROM IV00101 AS ['Item Master'] LEFT JOIN ( SELECT ITEMNMBR FROM POP10110 UNION SELECT ITEMNMBR FROM POP30110 UNION SELECT ITEMNMBR FROM POP10210 UNION SELECT ITEMNMBR FROM POP30210 UNION SELECT ITEMNMBR FROM SOP10200 UNION SELECT ITEMNMBR FROM SOP30300 UNION SELECT ITEMNMBR FROM IV30300 ) AS ['Used Items'] ON ['Used Items'].ITEMNMBR = ['Item Master'].ITEMNMBR INNER JOIN IV00102 AS ['Item Quantities'] ON ['Item Quantities'].ITEMNMBR = ['Item Master'].ITEMNMBR AND ['Item Quantities'].LOCNCODE = '' LEFT JOIN IV10301 AS ['Stock Count Line'] ON ['Stock Count Line'].ITEMNMBR = ['Item Master'].ITEMNMBR WHERE ['Used Items'].ITEMNMBR IS NULL AND ['Item Quantities'].QTYONHND = 0 AND ['Item Quantities'].QTYRTRND = 0 AND ['Item Quantities'].QTYINUSE = 0 AND ['Item Quantities'].QTYINSVC = 0 AND ['Item Quantities'].QTYDMGED = 0 AND ['Item Quantities'].ATYALLOC = 0 AND ['Stock Count Line'].ITEMNMBR IS NULL

If when you run the script you only get part of the macro text, you can change the query results length.

Permissions error exporting Microsoft Dynamic GP SmartList Object

Microsoft Dynamics GPA client recently reported a problem whereby users were no longer able to export a SmartList favourite to Excel as they were receiving a permissions error when the Excel file opened:

The SELECT permission was denied on the object 'uv_AZRCRVBudgetByMonth', database LIVE', schema 'dbo'

I did some checking and realised that the problem was that the file being opened when the user tried to do an export, was named like a Refreshable Excel report; a little more checking showed that there was a Refreshable Excel report of that name using the view from the SmartList. The SmartList object being used was using a SQL View to return the data and this had made the Publish button available. An accidental click had then published the Excel report, but, as the user did not have permissions to execute the view under their Windows account, the Excel report produced the error.

To confirm this I ran the below script to see what published Refreshable Excel reports were present:

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
SELECT DEX_ROW_ID FROM syDeployedReports WHERE ObjectType = 5

In this case, a few items were returned, but none of the SmartList Designer SmartLists should have been published, so I was able to take the above script and include it in a delete statement:

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DELETE FROM syDeployedReports WHERE DEX_ROW_ID IN ( SELECT DEX_ROW_ID FROM syDeployedReports WHERE ObjectType = 5 )

After running this, we just needed to delete the Excel report from the published location (same as the ones published from Reporting Tools Setup).

Now when a user tries to export the SmartList, the data is exported to Excel using the standard export function.

Jet Hub’s Supported Excel Functions

Jet HubI’ve been doing an increasing amount of work with Jet Reports and have come across two Excel functions which do not work with Jet Hub; they work fine in a Jet Report in Excel, but are apparently not supported in the Jet Hub.

The two I’ve encountered problems with are:

  • CONCAT isn’t supported, but the older CONCATENATE function is supported.
  • RATE; this was actually used by a client in a formula and we then discovered it wasn’t supported when uploading the report to jet Hub when I was showing him how to use it. We’ll need to find a way to work around this unsupported function.

There is a list of supported Excel functions in Jet Hub available from insight Software; I need to start referring to this list more often when creating reports and make sure clients do the same.

Select all user views and create GRANT SELECT TO DYNGRP statement

Microsoft Dynamics GPI have a Microsoft Dynamics GP project deployment coming up soon for a client project for which a number of SQL views have been created; I can easily grab a create script for the views from Object Explorer Details in SQL Server Management Studio, but I also need to create the grant statement to give permissions to Dynamic GP users to use the SmartLists Builder objects which use these views.

INFORMATION_SCHEMA.VIEWS is available for querying in SQL Server and allows you to get a listing of the views. The following script selects all views with my custom user view prefix (highlighted).

/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
SELECT CONCAT('GRANT SELECT ON ', TABLE_NAME,' TO DYNGRP', CHAR(13), 'GO') FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME LIKE 'uv_AZRCRV_%'

Run the script with the output set to text as for each view the script creates the GRANT and subsequent GO commands.

Jet Reports Snippet: Calculate last day of last month

Jet ReportsI’ve been doing some work with a client on Jet Reports recently and one of the items which we discussed, was running a report for the previous month without the user needing to set the date each time; this would allow them to use Jet Hub and schedule the report.

A few days ago, I posted an article on getting the last day of the month using an Excel formula. To get the date for use in Jet Reports, we can use the same formula, but can wrap it in an NP function to evaluate the formula:

=NP("Eval","=EOMONTH(Today(),-1)")

As you can see, the entire formula, which would usually be in the cell, has been included in the NP function wrapped in double quotes. Wrapping it in the NP function will ensure that the formula is calculated and the date available before other Jet functions run.

Custom Refreshable Excel Reports in Microsoft Dynamics GP navigation lists

Microsoft Dynamics GPMark Polino highlighted a post on Getting Custom with Excel Refreshable Reports on the Dynamics GP Support and Services Blog.

I’ve made a lot of use for clients on refreshable Excel reports and have made them available in the navigation list for clients (more recently, I’ve used that to make Jet Reports accessible in the same way):

Custom refreshable Excel reports in the navigation lists

Continue reading “Custom Refreshable Excel Reports in Microsoft Dynamics GP navigation lists”

SQL Stored Procedure to remove Jet Reports’ Report Run History

Jet ReportsIf you’re using Jet Hub with Jet Reports, then when you run a report, the report run is stored in the Jet Services database;through time, this report run history can grow quite large if you either have large reports or are generating lots of reports; combine these together and the history can grow to potentially massive sizes.

Jet Hub does not, unfortunately, include an automated clear-down routine for the report run history, but, fortunately, the history is only stored in a single table.

The below stored procedure can be created against the Jet Services database and scheduled to run with SQL Server Agent; the highlighted parameter at the top can be changed to alter the number of months for which history should be kept:

IF OBJECT_ID (N'usp_AZRCRV_DeleteJetReportsReportRuns', N'P') IS NOT NULL
    DROP PROCEDURE usp_AZRCRV_DeleteJetReportsReportRuns
GO

CREATE PROCEDURE dbo.usp_AZRCRV_DeleteJetReportsReportRuns
	@iAge INTEGER = 12
AS
/*
Created by Ian Grieve of azurecurve|Ramblings of a Dynamics GP Consultant (http://www.azurecurve.co.uk) This code is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0 Int). */
DELETE FROM ReportRuns WHERE Runtime < DATEADD(month, -@iAge, GETDATE()) GO

As always, test the script before using against a live system and ensure you have a good backup before

azurecurve ClassicPress Plugins: Nearby

ClassicPress PluginsThis is part of the which introduces the plugins I have available for ClassicPress.

The plugin I am going to cover in this post, is a brand new one I’ve developed to use on two of my other sies; Nearby.

Functionality

Nearby creates a table of nearby locations (pages) based on GPS co-ordinates; it integrates with Flags from azurecurve, to display a flag next to the location, and Toggle Show/Hide from azurecurve.

Apply the [nearby] shortcode to a page with co-ordinates and nearby locations (pages with co-ordinates), and based on the settings, nearby locations will be displayed in a table showing the distance.

Demo

Examples of this plugin in action can be found on coppr|Distilleries To Visit and DarkNexus|Tourist Attractions.

Download

The plugin can be downloaded via my Development site.

Excel Snippet: Get first day and last day of month using an Excel formula

Microsoft ExcelIt doesn’t come up very often as I do a lot of work using SQL Server rather than Microsoft Excel, but every so often I do need to do some date manipulation in Excel.

The formula, below, can be used to get the first and last days of a month (typically used for accruals); I had to do some research to find the syntax for Excel only to be surprised that it was similar to that of SQL Server (although both are Microsoft products so I maybe should not have been surprised).

Get last day of month:

=EOMONTH(TODAY())

Get last day of last month (same as above but subtract 1 within the function parameters to step back a month):

=EOMONTH(TODAY() , -1)

Get first day of this month (again using the EOMONTH function, but plus 1 outside of the function to add a day):

=EOMONTH(TODAY(), - 1) + 1

There is an alternate way of getting the first day of this month which uses a different function, but I find using EOMONTH easier to remember:

=TODAY() - DAY(TODAY()) + 1

The TODAY() function could be replaced with a table reference to calculate the first or last day of a month using other dates other than todays.