Unable to create a Consumer record in csm_consumer table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 07:34 PM
Hi All,
I am trying to create a consumer record in csm_consumer table but unable to do so as I am encountering following error while submitting the record. Anyone knows how to fix this?
***********************************************************************************************************
onSubmit script error: TypeError: Cannot read properties of null (reading 'getElementsByTagName'):
function onSubmit() {
var types =[];
$$(".location_types_class").each(function(el){
if (el.checked){
types.push(el.value);
}
});
var gr = new GlideRecord('cmn_location');
gr.addQuery('consumer',g_form.getUniqueValue());
gr.addQuery('primary','true');
gr.query();
if(gr.next()){
gr.setValue('type',types);
gr.update();
}else{
var changed = g_form.getValue('street') || g_form.getValue('city') || g_form.getValue('state') || g_form.getValue('zip') || g_form.getValue('country');
if(changed){
gr.initialize();
var name = g_form.getValue('street');
if (g_form.getValue('city'))
name += "," + g_form.getValue('city');
if (g_form.getValue('state'))
name += "," + g_form.getValue('state');
gr.setValue('name',name);
gr.setValue('primary','true');
gr.setValue('street',g_form.getValue('street'));
gr.setValue('city',g_form.getValue('city'));
gr.setValue('state',g_form.getValue('state'));
gr.setValue('zip',g_form.getValue('zip'));
gr.setValue('country',g_form.getValue('country'));
gr.setValue('consumer',g_form.getUniqueValue());
gr.setValue('type',types);
gr.insert();
}
}
}
***********************************************************************************************************
Any help is appreciated.
Thanks & Regards,
Gulzar Manuja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 09:27 PM
Hi @Ankur Bawiskar ,
Please accept my apologies if my response was ambiguous. I haven't written any new script. I am just trying to create one consumer record manually and I encountered the error while saving the record after filling in information like First Name, Last Name etc.
Since the error showed the code of the OnSubmit client script, I searched for the error code in the client scripts table and provided you the name of the client script. Hope it helps. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 09:32 PM
@Community Alums
Thanks for the detailed info.
that client script is for Case view, so are you in the correct view while submitting?
Is this error coming in another client instance (Test)?
Also try adding a try catch block to see the exceptio
the error is because of the line highlighted in bold
function onSubmit() {
//Type appropriate comment here, and begin script below
try{
var types =[];
$$(".location_types_class").each(function(el){
if (el.checked){
types.push(el.value);
}
});
var gr = new GlideRecord('cmn_location');
gr.addQuery('consumer',g_form.getUniqueValue());
gr.addQuery('primary','true');
gr.query();
if(gr.next()){
gr.setValue('type',types);
gr.update();
}else{
var changed = g_form.getValue('street') || g_form.getValue('city') || g_form.getValue('state') || g_form.getValue('zip') || g_form.getValue('country');
if(changed){
gr.initialize();
var name = g_form.getValue('street');
if (g_form.getValue('city'))
name += "," + g_form.getValue('city');
if (g_form.getValue('state'))
name += "," + g_form.getValue('state');
gr.setValue('name',name);
gr.setValue('primary','true');
gr.setValue('street',g_form.getValue('street'));
gr.setValue('city',g_form.getValue('city'));
gr.setValue('state',g_form.getValue('state'));
gr.setValue('zip',g_form.getValue('zip'));
gr.setValue('country',g_form.getValue('country'));
gr.setValue('consumer',g_form.getUniqueValue());
gr.setValue('type',types);
gr.insert();
}
}
}
catch(ex){
alert(ex);
}
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 10:33 PM
Hi @Ankur Bawiskar,
Yes, I am trying to create a consumer from Case view. Furthermore, I tried to create a consumer by requesting an instance from fundamentals course on Now Learning as well and I am getting the same error in that instance also. I will add try catch in the code and will share the results in some time. Thanks again !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2024 04:21 PM - edited ‎01-18-2024 04:26 PM
Hi @Ankur Bawiskar ,
I have added a try catch block as advised. Sharing the alert message:
As already pointed out by you, the issue seems to be due to the highlighted line of code. Since this script is out of the box, I am wondering why this issue is coming up in my personal instance and not yours. Could you please guide me what could be the probable reason for this error? Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2024 09:26 PM
Hi @Community Alums that's strange, have you done any customization on this OOB client script?
Harish