How do I set the caller field on an incident record created via a record producer?

nicholar
Kilo Contributor

I am developing an incident request form that uses:

  • a record producer to create incident requests.
  • a variable set that includes the caller's name (a reference field), short description (text field), description (text field), etc.The variable set also has an employee id number (text field)  
  • an OnChange catalog client script on the variable set that auto-fills the caller name based on what is entered in the employee id field.

If I submit the form by just typing in the caller's name in to the reference field the caller properly gets set in the record upon creation.

However, if I submit the form using the auto-filled field the caller gets left empty.

I can't seem to figure out why this is happening. In my record producer script I set the incident field using the following code:

        current.short_description = producer.short_description;

        current.description = producer.description;

        current.caller_id = producer.caller_name;

The description and short descriptions get set just fine on submission. Why isn't my caller being set?


As I mentioned this only occurs when the caller name is auto-filled on the form using the id number.

1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

Can I have a look at the onChange script? Are you using the sys_id of the user to auto-fill the caller name (i.e. the reference type variable)?


View solution in original post

3 REPLIES 3

Slava Savitsky
Giga Sage

Can I have a look at the onChange script? Are you using the sys_id of the user to auto-fill the caller name (i.e. the reference type variable)?


Here's my script:



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


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


          return;


    }



    //Type appropriate comment here, and begin script below


    var user = new GlideRecord('sys_user');


      user.addQuery('employee_number', newValue);      


      user.query();


      if(user.next()){


              g_form.setValue('caller_name',user.name);              


      }


}



I'm using the name of the user ... I will try using the sys id to see if that works



**UPDATE**


I changed the script to use the sys_id to populate the caller_name field and it now works!



I spent a while trying to figure this out and now that I see what the issue was I feel a little foolish.



Thank you so much for your help!


I am glad I could help.



The value of a reference field is always the sys_id of the record it points to. Just in case, detailed information about reference fields is available in the production documentation:


Reference Fields - ServiceNow Wiki