- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 11:33 AM
Is there a way to get the current catalog item's category using catalog client script?. Thanks in advance.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 12:30 PM
Hi Poornima,
Here is the script.
You have to create a client script.
var sys = g_form.getParameter("sysparm_id");
var ga = new GlideAjax('x_13241_smart_city.HelloWorld');//Replace the parameter with the API name of the script include you will create in the next step.
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_item_id',sys);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Create a script include
Name : HelloWorld
Client callable ; Checked
API Name : x_13241_smart_city.HelloWorld // Make sure you replace the API name with exactly as yours in the client script in the 2 nd line of code.
Script :
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
helloWorld: function() {
var sysId = this.getParameter('sysparm_item_id')
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', sysId);
gr.query();
while(gr.next())
{
return gr.name;
}
},
_privateFunction: function() { // this function is not client callable
}
});
});
I hope this helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 11:38 AM
Hi Poornima,
You can get the catalog item sys_id with the below line of code.
var a = g_form.getParameter("sysparm_id");
Then you can do the GlideAjax and query the category and return from the server.
I hope this helps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 12:30 PM
Hi Poornima,
Here is the script.
You have to create a client script.
var sys = g_form.getParameter("sysparm_id");
var ga = new GlideAjax('x_13241_smart_city.HelloWorld');//Replace the parameter with the API name of the script include you will create in the next step.
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_item_id',sys);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Create a script include
Name : HelloWorld
Client callable ; Checked
API Name : x_13241_smart_city.HelloWorld // Make sure you replace the API name with exactly as yours in the client script in the 2 nd line of code.
Script :
var HelloWorld = Class.create();
HelloWorld.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
helloWorld: function() {
var sysId = this.getParameter('sysparm_item_id')
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', sysId);
gr.query();
while(gr.next())
{
return gr.name;
}
},
_privateFunction: function() { // this function is not client callable
}
});
});
I hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 02:45 PM
Awesome. It worked. Thanks Pradeep

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2015 10:34 PM