Cannot create or update records in a custom table from workflow script

tim_sewell
Tera Contributor

First off, all of the operations work as expected when trying to create new, or update an existing record from the standard UI buttons.

That said, I have a custom table which extends from the Application table in the CMDB, cmdb_ci_appl.   I have not created custom access controls for the table.   I created a new Service Catalog item with variables for various columns in the custom table.   I have a workflow associated to the requested item, with script actions for Add and Update selections on the request form.

When Add is selected on a request form submission, the following code should create a new record in the table, but it doesn't do anything...   No record is created in the table, no errors are reported in the log, and the workflow shows that the step executes successfully.   I have stripped the code down to include 1 column, just the Name field.   Still, it will not create a new record:

var gr = new GlideRecord('u_lfg_application'); // this table extends the Application Table

gr.initialize();

gr.name = current.variables.lfgAppAddName; // String variable from request form

gr.insert();

If I change the code to reference the Application table, it works as expected, creating a new Application record:

var gr = new GlideRecord('cmdb_ci_appl'); // the Application table from the CMDB

gr.initialize();

gr.name = current.variables.lfgAppAddName; // String variable from request form

gr.insert();

The same behavior is experienced when trying to update an existing record in my custom table...

As I mentioned before.   If I navigate to my custom table in the UI, I can use the Add button and successfully create a new record.   Is there something I am missing that would also allow me to create records from a workflow script?

1 ACCEPTED SOLUTION

vant
Tera Expert

The only thing I can think of right now is to wrap that code into a function, since 'gr' is a very commonly used variable, there are likely collisions in the namespace. You can also add log statements between each line so you know exactly which step it fails or freezes at.


View solution in original post

2 REPLIES 2

vant
Tera Expert

The only thing I can think of right now is to wrap that code into a function, since 'gr' is a very commonly used variable, there are likely collisions in the namespace. You can also add log statements between each line so you know exactly which step it fails or freezes at.


tim_sewell
Tera Contributor

Genius!   Thank you!   Wrapped the code in a function and it works like a charm...