Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Autopopulate fields in Service Catalog form

Brian Sorensen
Giga 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
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
Tera Patron

Hi @Brian Sorensen 

 

Did you try with Auto Populate on variable?

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

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/atul_grover_lng [ Connect for 1-1 Session]

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