- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:20 AM
We have to get sys id of catlog item (current).
As per below code we have used getParameter() function, which is running fine on service now view, but not running for Service portal.
Any one knows alternative to get current sys id of catalog item in script include ?
Script include
var ApplicationModule = Class.create();
ApplicationModule.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCatItemAppMod: function () {
var cat_sys_id = this.getParameter('sysparm_cat_sys_id');
var gr = new GlideRecord('sc_cat_item');
//gr.addQuery('sys_id','b69a135f13967e00be19bda12244b0e7');
gr.addQuery('sys_id',cat_sys_id);
gr.query();
if (gr.next()) {
return "u_application=" + gr.u_application_name + "^u_module=" + gr.u_default_module;
}
return 'Yes to check';
},
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 02:56 AM
I got solution,
I have fetched sys id by below code , and passed that to script include ,
var Sysid = g_form.getUniqueValue();
Its running fine
Script Include
var ApplicationModule = Class.create();
ApplicationModule.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCatItemAppMod: function () {
var cat_sys_id = this.getParameter('sysparm_cat_sys_id');
var gr = new GlideRecord('sc_cat_item');
//gr.addQuery('sys_id','b69a135f13967e00be19bda12244b0e7');
gr.addQuery('sys_id',cat_sys_id);
gr.query();
if (gr.next()) {
return "u_application=" + gr.u_application_name + "^u_module=" + gr.u_default_module;
}
return ' ';
},
..........
Client script
function onLoad() {
//Apply a default filter to the list collector variable
var ga = new GlideAjax('ApplicationModule');
var Sysid = g_form.getUniqueValue();
ga.addParam('sysparm_name','getCatItemAppMod');
ga.addParam('sysparm_cat_sys_id',Sysid);
ga.getXML(setCollectorFilter);
function setCollectorFilter(response){
var catItemAppMod = response.responseXML.documentElement.getAttribute("answer");
var collectorName = 'rc_roles';
var filterString =catItemAppMod;
var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);
} }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:23 AM
g_form.getUniqueValue()
this should give you sys_id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:26 AM
Hi,
you need to get sysid from portal service script..and pass that as a parameter to your script include function
in widget server script..do like below
var itemSysId = $sp.getParameter('sys_id');
var ScriptInclude = new ApplicationModule().getCatItemAppMod(itemSysId);
then update script include function like below
getCatItemAppMod: function (itemId) {
var cat_sys_id = itemId;
(please mark helpful/like/correct if it helps)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:41 AM
Hi Rushit,
I am using same script include for service now form and service portal form , You mean I need to create separte script include for Service portal??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2017 01:51 AM
Okay I Just got it I have to add below code in widget service script, But I have added this two line in "SC Catalog Item " widget sever script. Getting error as not defined variable.
var itemSysId = $sp.getParameter('sys_id');
var ScriptInclude = new ApplicationModule().getCatItemAppMod(itemSysId);