Create a new entry in a customer table from a catalog items

steveturley
Tera Guru

Hi. I'm trying to create a new entry in a custom table from the value in a catalog item.

 

My table name is 'u_cmdb_ci_whitelisted_url' the field name I want to populate on the is 'name'

The field in my variables is called 'external_party_organisation_url'

 

Can someone advise if my script is correct please? (spoiler - it's not working currently!)

(function() {
        var server = new GlideRecord('u_cmdb_ci_whitelisted_url');
        u_cmdb_ci_whitelisted_url.initialize();
        u_cmdb_ci_whitelisted_url.name = current.variables.external_party_organisation_url;
        u_cmdb_ci_whitelisted_url.insert();
    }
}();

 

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage
Giga Sage

You need to use your server for calling function. The server variable holds the GlideRecord for your custom table u_cmdb_ci_whitelisted_url. please refer below.

 

 

(function() {
    var server = new GlideRecord('u_cmdb_ci_whitelisted_url'); // Use 'server' as the variable name
    server.initialize(); // Initialize the new record
    server.name = current.variables.external_party_organisation_url; // Set the 'name' field with the variable value
    server.insert(); // Insert the new record into the table
})();

 

 

  

View solution in original post

2 REPLIES 2

Gangadhar Ravi
Giga Sage
Giga Sage

You need to use your server for calling function. The server variable holds the GlideRecord for your custom table u_cmdb_ci_whitelisted_url. please refer below.

 

 

(function() {
    var server = new GlideRecord('u_cmdb_ci_whitelisted_url'); // Use 'server' as the variable name
    server.initialize(); // Initialize the new record
    server.name = current.variables.external_party_organisation_url; // Set the 'name' field with the variable value
    server.insert(); // Insert the new record into the table
})();

 

 

  

Fantastic! That works. Thank you. I didn't know that about 'server'. Is that because it's a custom table?