I’ve not searched for any other way to do this, but when i saw this community post here wanted to do it myself and this way:
Here we ,
Create a new field on Change_Request by the name Associate Request, which references to Request(sc_request) Table.
Creation of the Create a Service Request button on Change Request form :
Type : UI Action Name : Create a Service Request Client : checked onClick : addCatItem [javascript gutter=”true”] function addCatItem(){ //Open a dialog window to request items that we want to add. var dialog = new GlideDialogWindow(‘add_service_request’); dialog.setTitle(‘Select Request Item’); dialog.setPreference(‘sysparm_groupQuery’, ‘active=true’); dialog.render();
return false; }[/javascript] Type: UI Page Name : add_service_request [xml] <!–?xml version="1.0" encoding="utf-8" ?–> <table border="0"> <tbody> <tr> <td>Please select the Service Request which you want to order.</td> </tr> <tr> <td><!– Include the ‘ui_slushbucket’ UI macro –></td> <td align="right"><!– Include the ‘dialog_buttons_ok_cancel’ UI macro –></td> </tr> </tbody> </table>
[/xml] Client Script: [javascript] addLoadEvent(function(){ //Load the groups when the form loads document.getElementById(‘slush_right’).ondblclick = dbClick;
slush.clear(); var ajax = new GlideAjax(‘GroupCatalogItems’); ajax.addParam(‘sysparm_name’, ‘getItems’); ajax.getXML(loadResponse); return false; }); function dbClick(){ var sysID = gel(‘sys_uniqueValue’).value; url = ‘/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=’+this.value+’&sysparm_chg=’+sysID; window.open(url);
} function loadResponse(response){ //Process the return XML document and add groups to the left select var xml = response.responseXML; var e = xml.documentElement;
var items = xml.getElementsByTagName("item"); if(items.length == 0) return;
//Loop through item elements and add each item to left slushbucket for (var i = 0; i < items.length; i++) { var item = items[i]; slush.addLeftChoice(item.getAttribute(‘value’), item.getAttribute(‘text’)); } }[/javascript] Type: Script Include
Name : GroupCatalogItems [javascript] var GroupCatalogItems = Class.create();
GroupCatalogItems.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getItems : function() {
var gr = new GlideRecord("sc_cat_item");
gr.addQuery(‘active’, true);
gr.query();
//Add the available groups to select from
while (gr.next()) {
var item = this.newItem();
item.setAttribute('value', gr.getValue('sys_id'));
item.setAttribute('text', gr.getValue('name')); } }
});[/javascript] Creation of a Variable Set - Creation of a Variable - Creation of a Catalog Client Script on Variable Editor : [gallery]
Catalog Client Script :
[javascript] function onLoad() { var test = getUrlVars(); g_form.setValue(‘change_request’,test[‘sysparm_chg’]); }
function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf(‘?’) + 1).split(‘&’);
for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split(‘=’); vars.push(hash[0]); vars[hash[0]] = hash[1]; }
return vars; } [/javascript]
Please note, the important thing is to Add this Variable set to which all Catalog Items that you need to order from a Change Request.
Finally, to map, the change_request with the request, you need to write this Business Rule. Name : Assosiated Request Table : sc_req_item condition : !current.variables.change_request.nil() After : true When : Update [javascript] gs.addInfoMessage(‘Its getting inserted’); var gr = new GlideRecord(‘change_request’); gr.get(current.variables.change_request); if(gr){ if(gr.u_assosiated_request == ‘’){ gr.u_assosiated_request = current.request; gr.update(); } } [/javascript]
You should have the change_request in the requested item variable change_request .. you can access it using current.variables.change_request. And the above business rule will populate it in the Change Request table by populating the field Assosiated Request.