Is there a way of creating a routine to delete contacts on mass based on certain criteria?
Thanks
James
Is there a way of creating a routine to delete contacts on mass based on certain criteria?
Thanks
James
Hi James,
Not out of the box. A custom report could do it, but what kind of criteria’s did you think about ?
you can do that using a custom processingonly report or with a custom codeunit. but … be careful. you should check, if the contact is somewhere used before removing it. with dataitem property ReqFilterFields you can add filter fields, which are then shown in the report request form.
Hi Jonathan
Our sales team have a habit of creating blank contacts in error by the hundreds that are never used.
I would basically just want to remove these, as there are no interactions against them and never will be.
In an ideal world i would run the routine and select fields from the contact card as my criteria and delete.
For example, select maybe all contacts where the name, company name and post code are all blank.
Do you have any step by step instructions on how to do this, obviously I would try it out in my test environment first.
a simple solution could be:
create a new report with object id >= 50000. then add table contact as first dataitem. set property reqfilterfields of the dataitem e.g. to Name,Company Name,Post Code.
set cursor into last (empty) line in the designer. set report property processingonly to yes, confirm question (layout …) with yes.
write some code into trigger
Contact - OnAfterGetRecord():
IF ContactLoc.GET(Contact.“No.”) THEN
ContactLoc.DELETE(FALSE);
define a local variable ContacLoc (type rec, subtype Contact) for that trigger. the report runs through all contacts according the filter criteria. it’s always a good idea not to remove the current item within a loop, therefore is the local variable ContactLoc. the current contact is loaded into that local var., then it’s been removed using ContactLoc.DELETE(FALSE). using false as parameter means “do not run through the ondelete trigger in table contact”. if you do want the code to run through that trigger (removing all the connected data as well), then use true as parameter instead of false.
for sure there are many other solutions for that issue. an other simple solution is writing some code in a report with no dataitem, there into trigger onprereport or in a new codeunit in the onrun trigger like:
Contact.reset;
Contact.setrange(Name,’’);
Contact.deleteall(false);
a code like that can be used, if your filter criteria are always the same. the first solution provides a request page, where you set the filter criteria as you like. for entertainment it would be possible to create a progress bar (dialog).
Hi Jonathan
Thank you for this i will certainly give it a try. I like the idea of a progress bar, how do you create that?
Thanks
James
for creating a progress bar follow
https://msdn.microsoft.com/en-us/library/dd338672.aspx
http://dynamicsuser.net/forums/t/86855.aspx