- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2018 08:01 AM
Hi all!
I need some help with creating customer accounts in my instance.
Because of the OOTB logic of the account table (customer_account) being extended of the core_company table, logic dictates that records are created on the company table after creating an account record. The issue is that I'm working in an instance that is already being used for a couple of years now. So there are already company records in the system and I don't want to create duplicates. Removing (replacing) the original core_company records is not an option either as you will also lose your references in other parts of the system (e.g. on Incidents).
What can I do to link an account record to an existing company record?
Thanks in advance!
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 08:46 AM
Found a workaround. I created a background script to query for the right core_company records, and update the class:
//Fetch the record:
var gr = new GlideRecord('core_company');
gr.[insert query here];
//Switch the class:
if (gr.next()) {
gr.sys_class_name = "customer_account";
}
//Update the record (without triggering additional business rules (optional)):
gr.setWorkflow(false); //Optional.
gr.update();
It does what I need it to do and keeps all references intact. Yet this is but a workaround. A proper OOTB solution to this logical loophole would be welcome.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-05-2018 08:33 AM
Company table is the parent of Accounts table. So I do not think it is possible for you to create a child record without inserting into parent.
What you can try to do is to reverse what you are attempting to do. Insert child records for the company that is already present in company table to account table. You can use the setNewGuidValue method and try using the same sys id as the record on the core_company table. Use setworkflow(false) so that the script does not try to insert a record into core_company table.
Hope that works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 05:33 AM
Hi iamkalai,
Thank you for your response, however that will also not work due to the fact that ServiceNow is secured against sys_id duplication.
It returns this response:
java.sql.BatchUpdateException: Duplicate entry '[sys_id]' for key 'PRIMARY'
This is the quick and dirty script:
var companyRec = new GlideRecord('core_company');
companyRec.addQuery('name', current.name); //Name is unique in our case.
companyRec.query();
if (companyRec.next()) {
//In case the company was found, update the sys_id:
current.setNewGuidValue(companyRec.sys_id);
current.setWorkflow(false);
}
Something and somewhere about extended table records is doing something different upon creation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 06:08 AM
I do not see the insert statement here. Did you add current.insert while trying?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 07:06 AM
Hi iamkalai,
That is because I tested it with a insert business rule. In the new process a user is going to use the 'New' button to create an account.
Still, due to database consistency I'd expect ServiceNow to complain about sys_id duplication anyway.
Another thing I'd like to try is changing the class of the current company records to customer_account records.