Cannot insert a record in a custom table using while the record can be inserted in the parent table

B_22
Kilo Contributor

Hello,

I created code that inserts a new record in a custom class. This class is a child class of cmdb_ci. The code looks like this:

        new_si_support_record = new GlideRecord('support_ci');
        new_si_support_record.newRecord();
        new_si_support_record.po_number = "po number";
        new_si_support_record.model_id = cmdb_model_sys_id;
        new_si_support_record.operational_status = 1;
        new_si_support_record.name = "some name";
        new_si_support_record_sys_id = new_si_support_record.insert();

 

This does not work. When I change the first line to:

        new_si_support_record = new GlideRecord('cmdb_ci');

it does work.

The support_ci table is created in its own application/scope. So I checked the settings for application access on the table and enabled everything to be sure.

find_real_file.png

But still, I was unable to create a new record in the 'support_ci' table.

Because I am able to insert records into the cmdb_ci table, I assume the code is correct and the 'cross scope privileges' are sufficient.

What could be wrong?

20 REPLIES 20

B_22
Kilo Contributor

yes, but it did not work. But I noticed something strange in the logging...

Every function logs with source "***script" except my function where the record is added. This function logs with source "EMAIL.af11dd0a1b74c19018f0dd3fbd4bcbcd"

 

find_real_file.png

in an attempt to isolate the problem in the email action, I inserted a record at the top of the function. Although no record was inserted and the insert function returned null, no error was thrown.

 

find_real_file.png

Anil Lande
Kilo Patron

When you create a table in scoped application it's name would be like this:

find_real_file.png

 

Make sure you are using correct name in your scipt.

 

Thanks,

Anil Lande

B_22
Kilo Contributor

The name is correct. In the actual script, the name is x_spit_devops_si_o_si_support.

Dr_ Patrik Bich
Tera Contributor

Have you managed to figure it out?

If the table has been created in a scoped application, the table name does have the scope prefix (as mentioned by @Anil Lande)

If the table has been created in the global scope, the table name has a u_ prefix (e.g. in your case: u_support_ci).

 

try {
    var newSupportCiGr = new GlideRecord('u_support_ci');
    newSupportCiGr.newRecord();
    newSupportCiGr.po_number = "po number";
    newSupportCiGr.model_id = cmdb_model_sys_id;
    newSupportCiGr.operational_status = 1;
    newSupportCiGr.name = "some name";
    var newSupportCiSysId = newSupportCiGr.insert();
} catch (e) {
    gs.error(e.message);
}

 

Note: try to (1) declare variables, (2) use camel case for variable names (in order to avoid name clashes with field names).