Assign value to record producer variable via catalog client script?

smooradian
Kilo Expert

Need some assistance please with a catalog client script.

My question is this: Do you have to have a variable 1:1 on the catalog and the record producer in order to pass the value through to the variable on the record producer? If not, how do I write that code?

I've managed to pass through the variables 'category' and 'type' but only because the variables are both on the catalog and on the record producer.

What I'd like to do is for example, take the variable 'application' on the catalog   and that based on its value, let's pretend it's "salesforce", I'd like to auto-populate the variable 'portfolio' on the record producer with 'salesforce development'.

Is that possible?

below is my code for the catalog client script:

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == ''){

g_form.setVisible('sys_created_by',false);

  g_form.setVisible('category',false);

g_form.setVisible('type',false);

          return;}

//alert('load');

  var choice = g_form.getValue('request');

  //alert(choice);

if (choice == 'project') // project is the value of the choice

{

  //alert('inside');

  g_form.setValue('category','strategic');

  g_form.setValue('type','project');

}

if (choice == 'development') // development is the value of the choice

{

//alert('inside');

  g_form.setValue('category','strategic');

  g_form.setValue('type','enhancement');

}}

4 REPLIES 4

larstange
Mega Sage

Hi



You map the variables on the record producer with the record that will be created through the script field on the record producer (not in the client scripts)



You use the syntax



current.field_name = producer.variable_name;


Thanks Lars - your answer infers that the field must be on both the record producer and the service catalog. I'm trying to determine how you'd set a value on the record producer based on a value from the service catalog that doesn't map.


Kalaiarasan Pus
Giga Sage

When you say record producer, are you actually talking about record producer in ServiceNow or a table? The questions seems to be bit confusing when you use the terms of record producer and service catalog.


larstange
Mega Sage

If you dont have fields to map every value to, you would typically put the information in a description field or work notes as text.



To do this you construct a string to insert into the field:



var str = '';



str = "Here is a value: " + producer.variable_1 + "\nHere is a value from a reference variable: " + producer.variable_2.getDisplayValue();



current.description = str;