UI Action with g_form.getValue for a List-type Field

jlaue
Mega Sage

Hello - 

 

I have a UI Action that is checking for field values and then taking action from there.  If the field does not contain a specific value, then go ahead and proceed.  This was working great, however, the issue is that now the requirement is for this field to be a List type field, so I have created a new List type field that is referencing a table that contains the different choices.  I am not quite sure how to script this for a list-type field.  

 

Here is how it was prior to being a List-type field (accounting_close_code is the field that needed to be replaced for a List-type field):

 

if (g_form.getValue('accounting_close_notes') == '' && g_form.getValue('accounting_close_code') != "No Accounting Action Required") {

 

g_form.setMandatory('accounting_close_notes', true);

 

swal("Missing Information", "Please complete required fields prior to closing", "error");

 

return false; // Abort submission
}

 

Here is what I tried, but it is not working:

 

if (g_form.getValue('accounting_close_notes') == '' && g_form.getDisplayValue('accounting_close_code_list').toLowerCase().indexOf('no accounting action required') == -1) {

 

g_form.setMandatory('accounting_close_notes', true);

 

swal("Missing Information", "Please complete required fields prior to closing", "error");

 

return false; // Abort submission
}

 

Hoping this is possible within just the UI Action and my script is just incorrect ?  

 

Thanks!!

 

 

1 ACCEPTED SOLUTION

Alex Tod1
Kilo Sage

Hello @jlaue,

You could add this :

g_form.addInfoMessage('Close notes: '+g_form.getValue('accounting_close_notes');
g_form.addInfoMessage('Close code: '+ g_form.getDisplayValue('accounting_close_code_list'));

 

You could add these to the code to see what it returns, later we'll figure out if you're not getting the values right.

View solution in original post

3 REPLIES 3

jonsan09
Tera Sage

UI actions usually run Server side code, g_form is used for client side. You should be able to use current.field_name instead of g_form.getValue('field_name') I'd also recommend referencing the GlideRecord API documentation and checking how other UI actions are coded in your instance.

Alex Tod1
Kilo Sage

Hello @jlaue,

You could add this :

g_form.addInfoMessage('Close notes: '+g_form.getValue('accounting_close_notes');
g_form.addInfoMessage('Close code: '+ g_form.getDisplayValue('accounting_close_code_list'));

 

You could add these to the code to see what it returns, later we'll figure out if you're not getting the values right.

Thanks!  That helped a lot, I was able to get it sorted using the sysID for the one value I was checking.

 

g_form.getValue('accounting_close_code_list') != "d91302d11bd1f15096a79602b24bcbc2"