Client Scripting for triggering last order history for catalog item in servicenow portal and service
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2024 10:11 PM
Client Scripting for triggering last order history for catalog item in servicenow portal and servicenow instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 01:12 AM
Use below Client Script and Script Include to achieve this :
Client Script -
function onLoad() {
//Type appropriate comment here, and begin script below
var catalogSysID = g_form.getUniqueValue();
var requestorSysID = g_user.userID;
var ga = new GlideAjax('getCatalogLastUsedTime');
ga.addParam('sysparm_name', 'getCatalogSysID');
ga.addParam('sysparm_catSysID', catalogSysID);
ga.addParam('sysparm_usersysid', requestorSysID);
ga.getXML(OutputParse);
function OutputParse(response) {
var lastUsed = response.responseXML.documentElement.getAttribute("answer");
if (lastUsed == 'Catalog Item Requested for the first time') {
g_form.addInfoMessage('You are requesting this catalog item for the first time');
} else {
g_form.addInfoMessage('Last time, you requested this item on ' + lastUsed);
}
}
}
Script Include :
var getCatalogLastUsedTime = Class.create();
getCatalogLastUsedTime.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getCatalogSysID: function() {
var catalogSysID = this.getParameter('sysparm_catSysID');
var usersysID = this.getParameter('sysparm_usersysid');
var catItem = new GlideRecord('sc_req_item');
catItem.addEncodedQuery('requested_for='+usersysID+'^cat_item='+catalogSysID);
catItem.orderBy('sys_created_on');
catItem.setLimit(1);
catItem.query();
if(catItem.next()){
return catItem.sys_created_on;
}
else{
return "Catalog Item Requested for the first time";
}
},
type: 'getCatalogLastUsedTime'
});
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 10:00 PM - edited ‎02-01-2024 10:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 10:13 PM
Have you tested it from Service Portal or from native view ? Please try once with Service Portal as well if not.
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 10:40 PM
Hi @Amit Verma , I want this scenario means script will be execute for software category only , and this software category contains 20 catalog item , so this script execute for software category and individual catalog item .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2024 10:48 PM
So you want each and every catalog item under Software category to show the Last Used Date Time message. One way to do this is to have On-Load Catalog Client Script in all of these 20 catalog items which will call your script include but that's not feasible to do.
Let me think how we can do it as at least with Catalog Client Scripts, it is not possible as each and every catalog client script is unique to a catalog item. If we don't get any other solution, then probably you need to create On-Load Catalog client script for all the 20 catalog items under software category to call Script Include and show the message.
Please mark this response as correct and helpful if it assisted you with your question.