Widget returning [object Object]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 02:35 PM
Hey everyone,
I'm a little at my wits end here. I've trying to use the OOB Slush bucket widget on a catalog form to have it pull multiple values from a table and then have it fill to a variable (which will be hidden) on the same form.
Everything is working perfect, BUT (there's always a but) the values are passing from the widget as [object object].
Here's how i'm filling the selected values from the client script of the widget and filling into the form variable named, test.
$scope.$watch('c.selected.toString()', function(newVal, oldVal) {
$scope.page.g_form.setValue('test', newVal);
});
Here is the full Client Script:
// sample use of ng-sortable
function($scope) {
var c = this;
c.selected = [];
// ng-sortable clone means cannot reorder
c.availableAs = {
itemMoved: function (event) {
event.source.itemScope.item.used = true;
},
clone: true // clone this side
}
c.selectedAs = {
itemMoved: function (event) {
// moved back to available
var item = event.source.itemScope.item;
moveToAvailable(item);
removeItem(c.data.all, item);
},
dragStart: function () {
c.availableAs.clone = false;
},
dragEnd: function () {
c.availableAs.clone = true;
}
}
// double moves from Available to Selected
c.onDblClick = function(item) {
var t = angular.copy(item);
item.used = true; // original is now used
c.selected.push(t);
}
// double on selected removes and unsets Available used
c.onSelDblClick = function(item) {
moveToAvailable(item);
removeItem(c.selected, item);
}
function removeItem(array, item) {
var n = array.indexOf(item);
if (n !== -1)
array.splice(n, 1);
}
function moveToAvailable(item) {
var t = item.sys_id.value;
angular.forEach(c.data.all, function(target) {
if (target.sys_id.value == t)
target.used = false;
})
}
$scope.$watch('c.selected.toString()', function(newVal, oldVal) {
$scope.page.g_form.setValue('test', newVal);
});
}
Here is the server script:
(function () {
// grab names of available dependencies
data.all = [];
var fieldnames = "sys_id,label";
var gr = new GlideRecord('sys_choice');
gr.orderBy(fieldnames);
gr.query();
while (gr.next()) {
var t = $sp.getRecordElements(gr, fieldnames);
data.all.push(t);
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 10:36 AM
It's quite ok, haha. No worries.
I'm just mentioning it because we'd love to help you resolve your problem and with several threads (3) out there, it separates all the discussion.
Mike's given great advice here so hopefully you'll have your answer!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 10:44 AM
Mike is awesome! Your answers have also helped me many times! Take care
