- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2018 07:54 AM
When i open a new page with a simple list and form widget it opens with a default "Record not found". When you click on a record it displays the correct record. How do i get this to open the first record (or the latest record) without having to click on it first?
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2018 07:40 AM
Thanks, we went with a different solution in the end and thought i'd share.
Clone the Simple List widget.
change the Client Script
function ($scope, $location, $rootScope, spUtil, $interpolate) {
var c = this;
this.data.filterText = "";
this.showFilter = false;
this.onClick = function($event, item, url, action) {
$event.stopPropagation();
$event.preventDefault();
if (typeof url == "string") {
var urlExp = $interpolate(url);
url = urlExp(item);
$location.url(url);
} else if (url && typeof url == "object")
$location.search(url);
else {
var evt = {};
evt.url = url;
evt.table = item.className;
evt.sys_id = item.sys_id;
evt.record = item;
evt.rectangle_id = c.options.sys_id;
evt.action = action;
// put out the selection with simple list "sl_" prefix
$location.search('sl_sys_id', evt.sys_id);
$location.search('sl_table', evt.table);
$location.search('spa', 1); // spa means "I've got this"
$rootScope.$broadcast('$sp.list.click', evt);
}
};
this.onClickZero = function( item, url, action) {
if (typeof url == "string") {
var urlExp = $interpolate(url);
url = urlExp(item);
$location.url(url);
} else if (url && typeof url == "object")
$location.search(url);
else {
var evt = {};
evt.url = url;
evt.table = item.className;
evt.sys_id = item.sys_id;
evt.record = item;
evt.rectangle_id = c.options.sys_id;
evt.action = action;
// put out the selection with simple list "sl_" prefix
$location.search('sl_sys_id', evt.sys_id);
$location.search('sl_table', evt.table);
$location.search('spa', 1); // spa means "I've got this"
$rootScope.$broadcast('$sp.list.click', evt);
}
};
if (c.options.table)
spUtil.recordWatch($scope, c.options.table, c.options.filter);
this.getMaxShownLabel = function(maxEntries, totalCount) {
if (totalCount == c.data.maxCount)
return "${First [0] of more than [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
return "${First [0] of [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
};
this.seeAllPage = c.options.list_page_dv || 'list';
this.targetPageID = (c.options.sp_page) ? "&target_page_id=" + c.options.sp_page : "";
c.getActionColor = function(action) {
return "text-" + action.color;
};
c.update = function update() {
c.server.update();
}
c.toggleFilter = function() {
c.showFilter = !c.showFilter;
}
if(c.data.list){
this.onClickZero(c.data.list[0],c.data.list[0].url ,{});
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2018 01:48 PM
You could pass that page a url parameter so that the form widget will pull that from the url and display the record. You could also clone the widget and give it some sort of default value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2018 11:34 PM
You need to add some code into your Form Widget(cloned),so you can achieve requirement.
1.HTML
<div ng-init="init()">//first line
</div>//last line
2.Client
//add at immediate in function at starting place
$scope.init=function(){
$location.search("table",'incident');
$location.search("sys_id",$scope.data.arr[0].sys_id);
3.Server
//add at immediate in function at starting place
data.arr=[];
var gr = new GlideRecord('incident');
gr.orderByDesc(); //Descending Order
gr.query();
if(gr.next()){
var obj={};
obj.sys_id=gr.getValue('sys_id');
data.arr.push(obj);
}
It worked form me.
if in case any issue reply for same.
Regards,
Varsha.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2018 07:40 AM
Thanks, we went with a different solution in the end and thought i'd share.
Clone the Simple List widget.
change the Client Script
function ($scope, $location, $rootScope, spUtil, $interpolate) {
var c = this;
this.data.filterText = "";
this.showFilter = false;
this.onClick = function($event, item, url, action) {
$event.stopPropagation();
$event.preventDefault();
if (typeof url == "string") {
var urlExp = $interpolate(url);
url = urlExp(item);
$location.url(url);
} else if (url && typeof url == "object")
$location.search(url);
else {
var evt = {};
evt.url = url;
evt.table = item.className;
evt.sys_id = item.sys_id;
evt.record = item;
evt.rectangle_id = c.options.sys_id;
evt.action = action;
// put out the selection with simple list "sl_" prefix
$location.search('sl_sys_id', evt.sys_id);
$location.search('sl_table', evt.table);
$location.search('spa', 1); // spa means "I've got this"
$rootScope.$broadcast('$sp.list.click', evt);
}
};
this.onClickZero = function( item, url, action) {
if (typeof url == "string") {
var urlExp = $interpolate(url);
url = urlExp(item);
$location.url(url);
} else if (url && typeof url == "object")
$location.search(url);
else {
var evt = {};
evt.url = url;
evt.table = item.className;
evt.sys_id = item.sys_id;
evt.record = item;
evt.rectangle_id = c.options.sys_id;
evt.action = action;
// put out the selection with simple list "sl_" prefix
$location.search('sl_sys_id', evt.sys_id);
$location.search('sl_table', evt.table);
$location.search('spa', 1); // spa means "I've got this"
$rootScope.$broadcast('$sp.list.click', evt);
}
};
if (c.options.table)
spUtil.recordWatch($scope, c.options.table, c.options.filter);
this.getMaxShownLabel = function(maxEntries, totalCount) {
if (totalCount == c.data.maxCount)
return "${First [0] of more than [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
return "${First [0] of [1]}".replace('[0]', maxEntries).replace('[1]', totalCount);
};
this.seeAllPage = c.options.list_page_dv || 'list';
this.targetPageID = (c.options.sp_page) ? "&target_page_id=" + c.options.sp_page : "";
c.getActionColor = function(action) {
return "text-" + action.color;
};
c.update = function update() {
c.server.update();
}
c.toggleFilter = function() {
c.showFilter = !c.showFilter;
}
if(c.data.list){
this.onClickZero(c.data.list[0],c.data.list[0].url ,{});
}
}