- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 12:02 PM
I am trying to get the Sys_Id from the URL and then fetch the related records from a table.
I tried, data.sys_id = $sp.getParameter("sys_id"); in the server script ; but it doesn't fetch the sys_id from the URL.
Please assist.
Regards,
Yogesh PH
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 01:43 PM
Yogesh,
You want to use addQuery, as opposed to addEncodedQuery when looking up just the sys_id.
If you log ' $sp.getParameter("sys_id");', what does it return?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2016 05:50 AM
Hi Yogesh,
The syntax for addQuery is rec.addQuery('<field_name>', '<operator>', '<value>');. The operator is optional and will default to equals if not present.
You are missing the field name in your query.
Also, it is Best Practice to use an if instead of a while if you only expect one record to be return. This will stop a potential bad query from running on multiple records, which is especially helpful when using a delete function.
Read more about addQuery, and GlideRecord syntax on the Wiki at http://wiki.servicenow.com/index.php?title=GlideRecord#addQuery
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 04:57 AM
HI paulw(acorio),
the rec.deleteRecord(); function doesn't do anything in client script. I tried calling GlideAjax to delete but still no go. Do you know if we can run delete and update functions from service portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 05:18 AM
Yes, those functions work but only in the Server Script section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2016 05:19 AM
How can i call a server function from client?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2016 01:57 AM
Hi Yogesha,
You can use client controller to get URL parameters and send that to server side (submit request), please find below example
//Client controller
function ($rootScope, $scope, snRecordWatcher, spUtil, $location, $uibModal, cabrillo, $timeout,$window) {
var c = this;
c.data.table = $location.search().table;
c.data.rec_sys_id = $location.search().sys_id;
c.server.get( {action_name : 'validate', table: c.data.table, rec_sys_id : c.data.rec_sys_id } ).then(function(r) {
c.data.btn_visible = r.data.btn_visible; // r.data.btn_visible retrieve data from server controller
});
}
// Server controller
(function() {
if (input) {
if(input.action_name == 'validate') {
gs.log(input.table);
gs.log(input.rec_sys_id);
//validation
data.btn_visible = true;
}
}
});
Regards,
Chirag
@Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.