Reputation: 377
Is there a way to remove an existing site map with a customization project similar to adding one, or do we need to do a customization plugin to delete it?
Update:
I have been trying the solution below, but I keep getting errors. I searched for sitemap maintenance in the code and found a routine in the wizard logic, but it won't work in my code. I checked all the includes and I have everything I need.
The select below shows an error stating "An object reference is required for the non-static field, method or property 'PXSelectBase.Select(params object[])'"
using Customization;
using PX.Data;
using PX.SM;
using System;
...
/// <summary>
/// Delete site map entry
/// </summary>
/// <param name="screenID">Sitemap screen ID</param>
protected virtual void DeleteSiteMap(string screenID)
{
if (string.IsNullOrWhiteSpace(screenID))
{
throw new ArgumentNullException("screenID");
}
SiteMap sitemap = PXSelect<SiteMap, Where<SiteMap.screenID, Equal<Required<SiteMap.screenID>>>>
.Select(this, screenID);
return;
// Edit:
// starting 2017R2 there could be MUI* tables witch references to the sitemap. These are the new workspaces.
// It would be a good idea to check these tables for reference to the deleting screen. This script was written in 6.1 which did not have the modern UI workspaces.
}
Upvotes: 0
Views: 325
Reputation: 5613
The only way I have done this in the past was to use a customization plugin. You can query the sitemap table by screen id and delete it if found.
Something like this should work (although I have not tested this). I did pull some of it from our upgrade plugin for a quick sample:
protected virtual void RemoveSiteMapEntry(PXGraph graph, string screenId)
{
PX.SM.SiteMap siteMap = PXSelect<PX.SM.SiteMap,
Where<PX.SM.SiteMap.screenID, Equal<Required<PX.SM.SiteMap.screenID>>>>.Select(graph, screenId);
if (siteMap == null)
{
return;
}
graph.Caches[typeof(PX.SM.SiteMap)].PersistDeleted(siteMap);
// Edit:
// starting 2017R2 there could be MUI* tables witch references to the sitemap. These are the new workspaces.
// It would be a good idea to check these tables for reference to the deleting screen. This script was written in 6.1 which did not have the modern UI workspaces.
}
Alternatively you could write a PXDatabase.Delete
statement without the need of a PXGraph
. I only use PXDatabase
for upgrade logic or bulk processing of records when necessary.
All of these options you could call from a Customization Plugin. For a Graph you need to create a new instance before you can use it for my example.
Upvotes: 2