What can a Dynamic Creation Script access?

phsdm
Giga Expert

I have enabled the dynamic creation script in the Asset form's reference to Cost Center.   I want to create a Cost Center when an unknown value is entered.   But I have a twist:   I want to copy a type field's value from the Asset form to the new Cost Center record.

 

My dynamic creation script works fine when it is like this:

 

current.u_type = "wbs";

current.name = value;

current.insert();

 

But I want to get the type from the form.   It doesn't work for me like this:

 

current.u_type = g_form.getValue("u_charge_type");

current.name = value;

current.insert();

 

A related question.   How do I log from this script?   I tried jslog() and gs.log() but can't find the output.

6 REPLIES 6

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Unfortuntely g_form is a client side script so you can't run it here since this is server side code. It doesn't look like there is any way to access the form you're currently on as current in this context is an object representing the new record you're creating on the target table.



From this script, you would want to use gs.log() and access it through Script Log Statements module.



You could do something like add a before insert business rule that runs on your cost center table that queries the asset table for any asset related to the current cost center and copies that asset's charge type to your cost center record.


Thanks Brad.   I keep trying to use client-side features in this script, which of course does not turn out well.



My gs.log() statements seem to be going into the dumpster.



But I have stopped trying to do this with an Omit New script.   I am going to stick to dealer options and remove the trailer hitch from my sports car.


nsanderson
Tera Contributor

Hey, phscnp ....



You can access data from the "Form the reference field is on" by using "parent" in your creation script.



So for clarity...



current = record being "dynamically created"


parent = record that "Current" is being dynamically created from.



using your example script it would look like:



current.u_type = parent.u_charge_type


current.name = value;


current.insert();


Thank you nsanderson 😉

Definitely what i was looking for ! 

I don't understand why it's not documented on docs ...