[Fixed] SQLError: Cannot insert the value NULL into column 'Libr_LibraryId', table 'CRM.dbo.Library'; column does not allow nulls. INSERT fails

4 minute read time.

Hiya,

If you come across an error while upgrading from very older version that says: 

Errors 16 Items

                After line 40: SQLError: Cannot insert the value NULL into column 'Libr_LibraryId', table 'CRM.dbo.Library'; column does not allow nulls. INSERT fails (INSERT INTO Library (Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ('Letter', 'Marketing', 'Global Templates\US', 'Initial Inquiry Acknowledgment Template.html', 'Initial Inquiry Acknowledgment', 'Final', 'Y', 'US', 'Y', 'Y', 'Lead'); )

                After line 40: SQLError: Cannot insert the value NULL into column 'Libr_LibraryId', table 'CRM.dbo.Library'; column does not allow nulls. INSERT fails (INSERT INTO Library (Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ('Letter', 'Support', 'Global Templates\US', 'Case Progress Confirmation Template.html', 'Case Progress Confirmation', 'Final', 'Y', 'US', 'Y', 'Y', 'case'); )

This could be fixed by ES script provided below on 2025R2. (I have also attached the script as text document. Change the extension before using the file)

//Delete Library entries if existing 


RUNSQL("DELETE FROM Library WHERE libr_filename = 'Customer Service Response Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Case Progress Confirmation Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Complaint Resolution Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Case Update Notification Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Initial Inquiry Acknowledgment Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Product Information and Pricing Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Introduction to Sales Team Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Case Study-Success Story Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Prospecting Introduction Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Needs Assessment Letter Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Proposal Letter Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Thank you letter Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Letter to CEO Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Letter to CFO Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Letter to CTO Template.html' ");
RUNSQL("DELETE FROM Library WHERE libr_filename = 'Letter to COO Template.html' ");




//insert again 


RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Support',	'Global Templates\\US',	'Customer Service Response Template.html',	'Customer Service Response',	'Final',	'Y',	'US',	'Y',	'Y',	'case');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Support',	'Global Templates\\US',	'Case Progress Confirmation Template.html',	'Case Progress Confirmation',	'Final',	'Y',	'US',	'Y',	'Y',	'case');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Support',	'Global Templates\\US',	'Complaint Resolution Template.html',	'Complaint Resolution',	'Final',	'Y',	'US',	'Y',	'Y',	'case');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Support',	'Global Templates\\US',	'Case Update Notification Template.html',	'Case Update Notification',	'Final',	'Y',	'US',	'Y',	'Y',	'case');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Marketing',	'Global Templates\\US',	'Initial Inquiry Acknowledgment Template.html',	'Initial Inquiry Acknowledgment',	'Final',	'Y',	'US',	'Y',	'Y',	'Lead');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Marketing',	'Global Templates\\US',	'Product Information and Pricing Template.html',	'Product Information and Pricing',	'Final',	'Y',	'US',	'Y',	'Y',	'Lead');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Marketing',	'Global Templates\\US',	'Introduction to Sales Team Template.html',	'Introduction to Sales Team',	'Final',	'Y',	'US',	'Y',	'Y',	'Lead');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Marketing',	'Global Templates\\US',	'Case Study-Success Story Template.html',	'Case Study/Success Story',	'Final',	'Y',	'US',	'Y',	'Y',	'Lead');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Prospecting Introduction Template.html',	'Prospecting Introduction',	'Final',	'Y',	'US',	'Y',	'Y',	'Opportunity');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Needs Assessment Letter Template.html',	'Needs Assessment Letter',	'Final',	'Y',	'US',	'Y',	'Y',	'Opportunity');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Proposal Letter Template.html',	'Proposal Letter',	'Final',	'Y',	'US',	'Y',	'Y',	'Opportunity');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Thank you letter Template.html',	'Thank you letter',	'Final',	'Y',	'US',	'Y',	'Y',	'Opportunity');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to CEO Template.html',	'Letter to CEO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to CFO Template.html',	'Letter to CFO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to CFO Template.html',	'Letter to CFO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to CTO Template.html',	'Letter to CTO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to CFO Template.html',	'Letter to CFO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");

RUNSQL("INSERT INTO Library (Libr_LibraryId, Libr_Type, Libr_Category, libr_filepath, libr_filename, libr_note, libr_status, libr_active, Libr_language, Libr_Global, libr_mergetemplate, libr_entity) VALUES ((select top 1  Libr_LibraryId + 1 from [Library] Order by 1 desc), 'Letter',	'Sales',	'Global Templates\\US',	'Letter to COO Template.html',	'Letter to COO',	'Final',	'Y',	'US',	'Y',	'Y',	'person');");


Save the above in a document with extension .es

This script can be run with RunES tool present under location: FTP > Customer\SageCRM Tools\RunES

Copy the entire RUNES folder to your machine.

1. Backup the database.
2. Run the .es script using the instructions present under readme.md in the RunES folder

 

Parents Comment Children
No Data