- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2020 02:01 AM
What is the best way to get data from embedded widget into a catalog item variable? I am very new to Servicenow and feel like this is an easy question, but I haven't been able to find any easily understandable answer for a beginner. Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 06:07 AM
There is no direct way to get the values from the widget but you can use the below way to do that.
Create a hidden staging variable in your catalog item.
In your widget use the below code to get and set value from widget.
$scope.page.g_form.getValue('u_name');
$scope.page.g_form.setValue('u_name','test');
where u_name is the hidden variable you created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2020 06:10 PM
Hi Michael,
First you need to create your widget. Then create a catalog item variable. Set the type to micro. Go to the default value tab. Go to the widget field and select the widget you created. You should now see the widget when you view the catalog item in Service Portal.
thank you,
let me know if you have any further questions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2020 06:07 AM
There is no direct way to get the values from the widget but you can use the below way to do that.
Create a hidden staging variable in your catalog item.
In your widget use the below code to get and set value from widget.
$scope.page.g_form.getValue('u_name');
$scope.page.g_form.setValue('u_name','test');
where u_name is the hidden variable you created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-03-2020 02:22 AM
I was able to do it without having to call g_form.getValue(). Maybe this code snippet will help someone in the future. Thanks for the help. 🙂
function($scope)
{
var c = this;
var catalogItemVariableName = 'test_widget_variables';
var widgetArray = [];
c.add = function(){
widgetArray.push($scope.c.data.message);
replaceCatalogItemVariables(catalogItemVariableName, widgetArray);
c.data.action = 'addMessage';
c.server.update().then(function(){
c.data.action = undefined;
c.data.message = '';
})
}
}
//only checks if input value is array or string
function replaceCatalogItemVariables(fieldName, userValue)
{
if(Array.isArray(userValue))
{
$scope.page.g_form.setValue(fieldName, userValue.join('\n'));
}
else
{
$scope.page.g_form.setValue(fieldName, userValue);
}
}
}