How can I get the value of a field from the parent form in a catalog client script?

Community Alums
Not applicable

Hi all!

 

I have a OnSubmit Catalog client script that applies to a Variable Set. The type of the catalog client script is Service Portal / Mobile.  I need to get the value of a field from the parent form but this line of code is not working. Any idea why it doesn't work? 

var fieldName = g_service_catalog.parent.getValue('u_field_name');

 

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

This code will work to get the value of a variable that is defined on the Catalog Item.  Add an alert on 'fieldName' to your script.  If you are not getting the expect result then confirm your 'u_field_name' value exactly matches the name of a Catalog Item variable.

Ehab Pilloor
Mega Sage

Hi @Community Alums,

 

In a Service Portal or Mobile client script, the approach to accessing values from the parent form is slightly different compared to traditional catalog client scripts. Instead of using g_service_catalog.parent, you should utilize spModal to interact with the parent form. Here's the corrected code:

 

 
var fieldName = spModal.getField('u_field_name').getValue();
 
If you found this reply helpful, please mark it as solution/helpful.
 
Thanks and Regards,
Ehab Pilloor