Getting an error while creating a Consumer record in csm_consumer table.

Community Alums
Not applicable

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

5 REPLIES 5

Community Alums
Not applicable

Thanks for sharing. I will try to troubleshoot the script. 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Community Alums 

 

Greetings

 

Are you getting this script as error or do you have any error screenshot. 

 

Also

Do you rights to create the new record?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Community Alums
Not applicable

Hi @Dr Atul G- LNG .
Hope you are doing well. 
Thanks for your response. This is the error message I am getting when I am trying to save the consumer record after filling in some information like First Name, Last name:

GulzarManuja_0-1705622127356.png

I checked the code in the error message and it is pointing me to 'Set type values' client script on Consumer table. Hope this helps. Thanks. 

Hi @Community Alums 

You reached at point, check that script.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************