Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Autopopulate fields in Service Catalog form

BrianS344076034
Tera Guru

Im sure this is simple and i'm just overthinking it...

 

I have a form that points to specific hardware in the peripheral table (cmdb_ci_peripheral)

 

I want to do the following

Select Box - user selects the peripheral < this works

Then Autopopulate the following fields

MAC Address

Serial Number

IP Address

 

Looking at the table view my assumption is that the names are

mac_address , serial_number, ip_address

 

When I try and script this for onChange I am doing the following - any idea where I missed?

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var user = g_form.getReference('existing_unit_name', populateReqForDetails);

function populateReqForDetails(cmdb_ci_peripheral) {
g_form.setValue('existing_mac_address', cmdb_ci_peripheral.mac_address);
 
g_form.setValue('existing_serial_number', cmdb_ci_peripheral.serial_number);
g_form.setValue('existing_ip_address', cmdb_ci_peripheral.ip_address);
 
}
}
 
3 REPLIES 3

jamhoe
Tera Expert

Hi Brian,

 

I suggest you use GlideAJAX since getReference() is not a recommended practice anymore for retrieving data due to their performance impact.

 

This thread could guide you on how to retrieve the needed data from SN tables using GlideAJAX:

https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet/ta-p/2312430

 

Hope it helps! 

ersureshbe
Giga Sage

Hi, 

Is the field name correctly called in the script i.e., existing_unit_name?

Next - Onchange script based on what field selection the below code is running? did you verify it?

Regards,
Suresh.

Dr Atul G- LNG
Tera Patron

Hi @BrianS344076034 

 

Did you try with Auto Populate on variable?

 

 

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************