Skip to main content

Notifications

Microsoft Dynamics GP (Archived)

Clear Company Script fails

Posted on by 75,730

I am running the latest version of the Clear Company scripts and I am getting this message on every company. 

"Conversion failed when converting the varchar value 'MyInterID' to data type int.

The other odd thing is I cannot add the TWO company. GP Utilities goes through all the motions but the record for TWO never gets added to the SY01500 table.

Has anyone ever experienced this? Any clues as to how to correct?

*This post is locked for comments

  • Suggested answer
    John S Miele Profile Picture
    John S Miele 132 on at
    Clear Company Script fails
    I ran into the same issue where the clear companies script failed.  It actually failed on a table called "GSCOMBINE".  It turns out the table is used by the  Greenshades Addon.  Here is the response from Greenshades Support back in March, 2018:
     
    The GSCOMBINE table is a temporary table in which companies are combined for combined filings. You are more than welcome to skip, or truncate the table. You will select the companies to be combined within the application. Our team will look into the data structure for potential improvements. Please let us know if you have any further questions, or need assistance.
     
    We added the exception to this table to the clear companies script and voila, it worked.  The issue could occur with other add-ons that use the companyid field as varchar.  
     

     
  • Suggested answer
    Beat Bucher  GP Geek  GPUG All Star Profile Picture
    Beat Bucher GP Gee... 28,021 Super User 2024 Season 1 on at
    RE: Clear Company Script fails

    Never Mind,

    I found out why the ClearCompany script would fail... :-)

    I ran the whole script in debug mode in SSMS and when it failed it was because it was trying to delete entries from a table called 'syDeployedReports_bak', which of course wasn't part of the exclusion in the script itself, thus it would be considered as a regular user table to check for CompanyID..

    So the script actually works, just be careful there is no copy or backup table of the syDeployedReports object !

    PS: I actually improved the script itself, as the syDeployedReports table would be left with orphaned entries from the process after the clean-up. I added the following statement right after the 1st line with the declare statement to start loopin the GPsystem table. 

    DELETE FROM dynamics..syDeployedReports WHERE CompanyID NOT IN (SELECT INTERID FROM DYNAMICS..SY01500)

  • Beat Bucher  GP Geek  GPUG All Star Profile Picture
    Beat Bucher GP Gee... 28,021 Super User 2024 Season 1 on at
    RE: Clear Company Script fails

    I'm actually stumped, because the latest script version I have that is supposed to work for all GP versions from G10 to 2016 already includes a section of the code to ignore the 'syDeployedReports' table, but it doesn't seem to work

    declare companyID_Cleanup1 CURSOR for
     select ''delete '' + rtrim(o.name) + '' where companyID not in (0,-32767)
       and companyID not in (select CMPANYID from SY01500)''
     from sysobjects o join syscolumns c on o.id = c.id and o.type = ''U''
     where c.name = ''companyID'' and o.name <> ''SY01500'' and o.name <> ''syDeployedReports''
     order by o.name

    open companyID_Cleanup1
    fetch next from companyID_Cleanup1 into @statement
    while (@@fetch_status <> -1) begin
     exec (@statement)
     fetch next from companyID_Cleanup1 into @statement
    end
    close companyID_Cleanup1
    deallocate companyID_Cleanup1

    declare companyID_Cleanup2 CURSOR for
     select ''delete '' + rtrim(o.name) + '' where companyID <> ''''' + rtrim(@GPSystem) + '''''
       and companyID <>'''''''' and companyID not in (select INTERID from SY01500)''
     from sysobjects o join syscolumns c on o.id = c.id and o.type = ''U''
     where c.name = ''companyID'' and o.name <> ''SY01500'' and o.name = ''syDeployedReports''
     order by o.name
    open companyID_Cleanup2
    fetch next from companyID_Cleanup2 into @statement
    while (@@fetch_status <> -1) begin
     exec (@statement)
     fetch next from companyID_Cleanup2 into @statement
    end
    close companyID_Cleanup2
    deallocate companyID_Cleanup2

  • Suggested answer
    Beat Bucher  GP Geek  GPUG All Star Profile Picture
    Beat Bucher GP Gee... 28,021 Super User 2024 Season 1 on at
    RE: Clear Company Script fails

    Hi Derek Albaugh

    I know this is old stuff, but it comes back on a recurrent basis and bites us everytime we try to run the ClearCompany script to clean-up old references, but then if fails invariably on the convert issue when Excel or SSRS reports are deployed within GP.

    Will anyone ever fix this script to get this sorted out? since it's a known issue and we know that the culprit lies in the syDeployedReports table, why don't simply fix it ? 

    Every once in a while when you stumble across this bug, you don't remember the exact cause and have to start searching the internet about a solution, whereas this could be a pretty simple thing to be fixed I guess.. 

    Thanks for your insights. 

    PS: modify the ClearCompany script to take into account that particular table, or fix the deployement of reports process and replace the value from "CompanyID" by the true ID or change the name of the column to match the "INTERID" name of the SY01500 table. 

  • Dae Profile Picture
    Dae 45 on at
    RE: Clear Company Script fails

    Thank you very much! I will do that!

  • RE: Clear Company Script fails

    Hello Danae,

    Normally when the ClearCompanies script fails, it'll throw an error message about what the varchar value is that it is trying to an integer value but cannot, similar to the error at the very beginning of this forum post.

    What you'll need to do is run a script or something looking for that value in the tables of the DYNAMICS/system database, then when you find what table/columns this value is in, verify that it is a column setup as a varchar and not an integer.

    As mentioned above, the most common table that causes this is the syDeployedReports table, you can try making a backup of that database, truncating this table, run the ClearCompanies script then if it is successful, put the data back into this table.

    Thanks

  • Dae Profile Picture
    Dae 45 on at
    RE: Clear Company Script fails

    Hello Derek, I am having the same issue when running the ClearCompanies script under my Test environment.  How can I solve this issue? I need to run this script because we deleted a company database in SQL Server Management Studio before it was deleted from Microsoft Dynamics GP.

    Thank you!

  • RE: Clear Company Script fails

    Hello Richard,

    The main problem with the syDeployedReports table is that it has the 'CompanyID' column as a varchar data type, whereas, every other table that has a companyID or CMPANYID column, such as the SY01500 table (Company Master) that it references, is setup as a smallint data type.

    The issue with the ClearCompanies script is that it attempts to compare the company ID values from other tables to the SY01500 and runs into an issue when it has a varchar value trying to compare it to a smallint value, thus the error message.

    This is why the syDeployedReports table is probably 99% of the issues we see running the ClearCompanies script.

    Thanks,

  • Beat Bucher  GP Geek  GPUG All Star Profile Picture
    Beat Bucher GP Gee... 28,021 Super User 2024 Season 1 on at
    RE: Clear Company Script fails

    Hi Richard,

    The version I have for the ClearCompanyDB script is dated June 2014 & supposed to be compatible with GP 2013 and the SL Designer..

    I woulnd't have suspected that the syDeployedReports could be causing issues here.. but nonetheless, ths is one of those tables you have to be very careful when creating a new TEST enviornment for a future upgrade.. read on here

    As explained by Microsofot (Sarah Purdy) here (blogs.msdn.microsoft.com/.../microsoft-dynamics-gp-ssrs-reports-and-deployment), GP Utilities automatically re-deploys SSRS & Excel reports based on the content of this table, whith the adverse effect of scrapping your existing enviromnet if you don't change the values inside that table first.

  • Verified answer
    Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: Clear Company Script fails

    The problem was with this table -  DYNAMICS..syDeployedReports. I had to remove the SY01500.INTERID value for each company. Once I did that the ClearCompany script ran with no issues and the TWO company is now created. This is very odd and one night when I cannot sleep I will try to figure out what caused this.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans