g_form.getOptions not working in the portal. alternative

lomouhamadou
Kilo Guru

Hi all,

With the new service portal g_form.getOptions is not working and using g_form.getValue will return the value and not the display value which is a string.

GetOption is not handle by the portal

Has anyone an idea or alterntive?

Regs,

Lô Mouhamadou

8 REPLIES 8

Hi,
@Brad @Chuck,
what about using g_form.getDisplayValue() to get choice Label in current user Language instead of g_form.getOption() since it's not working on Service Portal ( for now...) ?

from the Old wiki :

 var choiceValue = g_form.getValue('category');
 var choiceLabel = g_form.getOption('category', choiceValue).text;

turn into

	var choiceValue = g_form.getValue('your_field_Name');
	var choiceLabel = g_form.getDisplayValue('your_field_Name');

 It's working with Service Portal on Desktop, but is it a good practice to use here, or we could have some issue ? what about Mobile.

Regards,
Denis.

 

I answer to myself : some methods are deprecated and could stop to work in future versions :

More from Docs here :

Mobile client GlideForm (g form) scripting and migration

https://docs.servicenow.com/bundle/london-application-development/page/script/client-scripts/referen...

This works for me!. Thank you very much

I am trying to set an item in a record producer variable with Multiple Choide and get the Text of the Multiple Choide on OnSubmit in the catalog client script.

 

var choiceValue = g_form.getValue('your_field_Name');
var choiceLabel = g_form.getDisplayValue('your_field_Name');

 

In either of the above methods, the Value is retrieved, not the Text.

In the case of a Select Box item, not Multiple Choide, the Text is successfully obtained by getDisplayValue().

 

Also, in the case of OnChange, not OnSubmit, the Text is successfully obtained by getDisplayValue() even in the case of Multiple Choide.

Is there any way to get the Text of Multiple Choide when OnSubmit?

 

Thank you in advance.