Dynamic Helper Text on Variables

lpruit2
Kilo Sage

Greetings all,

 

I was wonder if it was possible to have a dynamic helper text for a Variable within a Variable set using the g_form.getControl or g_form.getElement APIs. The use-case is that I have a Variable Set with, lets say, 10 Variables in the set. The plan is that multiple people can utilize this Variable Set in their own individual Record Producer and Catalog Items. I want to be able to accomodate that different individuals using this VS can customize the helper text that they wish to use for their RP or CI WITHOUT impacting others. Is there a way to dynamically set the helper text by scripting using one of the two above mentioned methods? Any information that anybody wishes to share would be greatly appreciated. 

 

P.S. Currently I am working around this by using Field Messages but would be interested to learn if it is possible to script the helper text as that grants me access to the collapsable text. 

4 REPLIES 4

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @lpruit2,

 

Here is what i see, that use case which you shared is not a common use case were the majority of customers would opt for. There are ways to attain it diffrent track and objectives. As you have opted for field message, i would say that in your case that would be the best fit to utilize a given field which can be use by a individuals  in diffrent ways.

 

You can go for client script to dynamically change the field info message as per conditions.

You can opt for duplicate fields with same purpose having diffrent help text in them and control it via client script for field visiblity.

 

I hope this helps...


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Juhi Poddar
Kilo Patron

Hello @lpruit2 

There isn’t a straightforward way to dynamically change the helper text of a variable within a Variable Set based on the Catalog Item or Record Producer context. However, a workaround is possible.

You can create duplicate variables within the Variable Set—each with the desired helper text customized for different use cases. Then, in the Variable Set client script, hide all the variants by default:

function onLoad() {
   //Type appropriate comment here, and begin script below
   g_form.setVisible('variable1', false);
   g_form.setVisible('variable2', false);
   g_form.setVisible('variable3', false);
}

Next, in the Catalog Item or Record Producer-specific client script, selectively show the relevant variable based on the context:

function onLoad() {
    g_form.setVisible('variable1', true);
}

This approach keeps the Variable Set reusable while allowing flexibility in what helper text is displayed per Catalog Item, without impacting others.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

lpruit2
Kilo Sage

Thanks to everybody for their help so far. I understand that creating multiple Variables with the individual Helper Text would be one approach. I am still looking for somebody who is more familiar with the g_form.getControl('variable_name') method? When I use Dev Tools on the page while focusing on the field I have made a note of some of the HTML elements. 

id

class

onkeypress="toggleVariableHelpTextKeyEvent(event);"

onclick="toggleVariableHelpText(this);"

role="button"

aria-expanded="false"

aria-controls="question_help_ni_[....._toggle_value">More information<span class="sr-only">about Variable </span></span>

Has anybody used .getControl to manipulate or directly access any of the HTML elements? 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@lpruit2 

I don't think you can set help text dynamically as per my experience

You can try to use variable of type "Custom" having widget which will observe and show the help text, but it would be heavy customization and not recommended.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader