How to insert a label_entry via client script

Cort1
Tera Expert

I would like to automatically add a tag to an incident when a state is changed and a user is prompted. Here is my client script code:

var lab = new GlideRecord('label_entry');  

  lab.initialize();  

  lab.title = 'Incident - ' + g_form.getValue('number');  

  lab.label = '6120c3ed4f383600847c2f9ca310tr45e';   // defined label KB REFERENCED

  lab.url = 'incident.do?sys_id=' + g_form.getUniqueValue() + '&sysparm_view=';

  lab.id_display = g_form.getValue('number');

  lab.id_type = 'incident';  

   

  lab.table = (g_form.getTableName());  

  lab.table_key = (g_form.getUniqueValue());

  lab.insert();

The label entry is inserted but the table and table_key fields are absent. I also notice a message in the error log:

Table name cannot be null: java.lang.IllegalStateException: Table name cannot be null: com.glide.db.TableDescriptor.<init>

The tag does not show up on the incident. I must be doing something wrong with how the table is getting passed. Any thoughts?

1 ACCEPTED SOLUTION

Cort1
Tera Expert

I had to do this through an Ajax call /script include and it was able to work.


View solution in original post

1 REPLY 1

Cort1
Tera Expert

I had to do this through an Ajax call /script include and it was able to work.