How to insert records through a scheduled server script within a custom application

wolfgangb
Giga Contributor

I am in the process of converting a global scheduled job script into a custom scoped application. The job should fetch some data from an external service, fill the application scope local table with data.

Inserting records into global tables from a global scheduled script works well with following script:

var srv = new GlideRecord("cmdb_ci_server");

srv.get("correlation_id", hKey);

srv.correlation_id = hKey;

srv.host_name = "testhost";

srv.updateWithReferences();

When I try to run this script within a custom application on a custom application table I am not able to insert anything.

What am i doing wrong?

1 ACCEPTED SOLUTION

Ok finally i got it working. The problem was that i was not using the newer 'scoped scripted API' that can be found here:


ServiceNow Developers



then this script actually works for me without problems:



var srv = new GlideRecord('cmdb_ci_server');


srv.initialize();


srv.setValue('host_name', 'testhost');


srv.insert();


View solution in original post

7 REPLIES 7

Hi Wolfgang,



OOTB you should be able to create/update record on this table from other scope. However can you please check if can create/can update checkbox(Go to the table "cmdb_ci_server" and related list "Application Access settings")   is set to true for other scopes in your instance.


More info here


Application Access Settings - ServiceNow Wiki


screen.png


Access definition for the table, should be ok as i see it.


Ok finally i got it working. The problem was that i was not using the newer 'scoped scripted API' that can be found here:


ServiceNow Developers



then this script actually works for me without problems:



var srv = new GlideRecord('cmdb_ci_server');


srv.initialize();


srv.setValue('host_name', 'testhost');


srv.insert();