i want use g_form in widget

HUANGCONG
Tera Contributor

In catelog item,i create a Custom with Label variable 。

Then create a html widget

Now i want to use g_form in widget Client Script.

How can i do 

 

 

3 REPLIES 3

Community Alums
Not applicable

Hi @HUANGCONG ,

g_form does not work there, to get a value in a client controller you can use something like this:

 

$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'your_field')
    c.data.yourfield = parms.newValue;
});

 

Or refer to these links :

https://www.servicenow.com/community/developer-forum/how-to-use-g-form-submit-in-a-widget-for-servic...

https://www.servicenow.com/community/developer-forum/unable-to-access-g-form-in-widget-code/m-p/1847...

 

Prarthana Patil
Tera Expert

Hi,

 

"g_form" as a global object cannot be used in a widget client controller so its functions are not supported either. Please find below link for solution.

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715296

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."

 

Regards,

Prarthana Patil

Anurag Biswas
Tera Contributor
It would be better to know what exactly you want to do in the widget's client controller . You may use something like below ->
 
var g_form = $scope.page.g_form;
 g_form.setValue('variable_name', 'value');