Reputation: 126
I am new to ServiceNow. I have created a Catalog Item along with a simple workflow to approve the request and then call a script that will fetch the form's field values and further call a REST API. My form has 4 fields with there variable names as follow - name, operating_system, instance_type, storage I am not able to fetch the values for these fields in the script. Here is my code snippet which I am trying to get the value -
var vm = g_form.getValue('name');
and second way -
var vm = current.name;
Both of these ways are not working. In second way I am getting undefined and in the first way script is not getting processed further without giving an error. Please help. Thanks in advance.
Upvotes: 0
Views: 10054
Reputation: 1
You can get Variables from Catalog Item by using
current.variables.backend_value_of_variable
Replace backend_value_of_variable with your
Upvotes: 0
Reputation: 1596
You didn't specify the context of your script that needs the variable values. (Service catalog fields are "variables", and they are different from normal table fields). What kind of script object are you coding here?
Client-side gets them via g_form.getValue("field_name");
Server-side gets them via ritmGlideRecord.variables.field_name (or for dynamic field name, ritmGlideRecord.variables[fieldName]). For several script types the RITM Glide Record is available as JS variable 'current'. Other times you'll need to do a GlideRecord query to get it.
Upvotes: 0