set default value on a Catalog Item form variable to answer of other variables

kevinray
Giga Expert

Hi.

My customer has a form that asks a set of questions.

They have the ability (in the form) to set what they want the short description of one of the tasks in the workflow to be (it's one of the form fields they fill in)

The variable is simply called Task Short Description. They fill that in and when that task activates in the workflow, the short description will be whatever they put in that field. Easy.

They are asking now, if that field could be pre-populated with a combination of two other fields on the form they fill out before they get to that field, but editable so they can change it if they want before submission. (the idea is it saves them key strokes if they don't need to change it)

I've tried to use javascript to set the default value to be the the two fields concatenated, but my guess is that 1) i'm not using the proper calls, or 2) because they really haven't been set yet (because it's a web form) it's not working.

Here's how it would work (example)

They click catalog item to order.

They are presented the form to fill out:

Request type (is a drop down) (Create Access, Remove Access,

Application Name (Is a reference to the CMDB)

Task Short Description (text field that would be default to'Request Type' +   " - " + 'Application Name') RESULT: "Create Access - ACME".

They want this editable so they can change it if they want, but would save them keystrokes if it was pre-populated

My other option was to set this short description in the workflow, and just do a check (if null, then set short description to Request Type' +   " - " + 'Application Name', else set it to whatever they put in the field.)

I didn't want to go this way if at all possible, because there are so many agents filling this in it just creates less confusion if they can just see what it will be before they submit.

1 ACCEPTED SOLUTION

Something like this:



find_real_file.png


View solution in original post

4 REPLIES 4

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi,



To get this to work you need to have a onChange Catalog Client script. I would put that on the second field "application name" so when it's filled in, the client script would set the value on "task Short Description".



//Göran


Something like this:



find_real_file.png


YES! Thank you sir. I figured i was just not coding correctly. {just a newbe }



One of the fields is actually a lookup so i had to get it's 'name' but couldn't have done it without you!!! THANK YOU!



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


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


  return;


  }


var appname = g_form.getReference('gr_application_name');


  data = g_form.getValue('gr_access_type') + " - " + appname.name;


  g_form.setValue('gr_task_1_short_description', data);


  //Type appropriate comment here, and begin script below



}


Happy to help



//Göran