Service portal i need to redirect to RITM

bhuvana
Kilo Guru

Hi Community,

I want to trying after submitting the form i got a pop-up message like''click here to view'' . After clicking on this link i need to redirect to RITM but it redirects to Request .how can i achieve this i post a code which i was used for redirecing..

Please let me know if you have any doubts.

SERVER SCRIPT:

                // populate the 'data' variable with catalog item, variables, and variable view

(function() {

options.show_add_cart_button = (options.show_add_cart_button == "true");

if (options.page) {

var pageGR = new GlideRecord("sp_page");

options.page = (pageGR.get(options.page)) ? pageGR.getValue("id") : null;

}

if (options.table) {

var tableGR = new GlideRecord("sys_db_object");

options.table = (tableGR.get(options.table)) ? tableGR.getValue("name") : null;

}

options.url = options.url || "?id={page}&table={table}&sys_id={sys_id}";

data.showPrices = $sp.showCatalogPrices();

var m = data.msgs = {};

m.submitMsg = gs.getMessage("Submit");

m.submittedMsg = gs.getMessage("Submitted");

m.createdMsg = gs.getMessage("Created");

m.trackMsg = gs.getMessage("track using 'Requests' in the header or");

m.clickMsg = gs.getMessage("click here to view");

m.dialogTitle = gs.getMessage("Delete Attachment");

m.dialogMessage = gs.getMessage("Are you sure?");

m.dialogOK = gs.getMessage("OK");

m.dialogCancel = gs.getMessage("Cancel");

m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} - please try again", "24MB");

//K17 Updates - Starts

data.isLike=false;

var gr2 = new GlideRecord('u_favorite_catalog_items');

gr2.addQuery('u_catalog_item',$sp.getParameter('sys_id'));

gr2.addQuery('u_user',gs.getUserID());

gr2.query();

if(gr2.next()){

    data.isLike=true;

}

if(input && input.action=="Insert"){

var gr2 = new GlideRecord('u_favorite_catalog_items');

gr2.addQuery('u_catalog_item',input.catID);

gr2.addQuery('u_user',gs.getUserID());

gr2.query();

data.isLike=true;

if(!gr2.next()){

gr2.u_catalog_item=input.catID;

gr2.u_user=gs.getUserID()

gr2.update();

}

gs.addInfoMessage('Added to your favourites');

}

if(input.action=="Delete"){

var gr1 = new GlideRecord('u_favorite_catalog_items');

gr1.addQuery('u_catalog_item',input.catID);

gr1.addQuery('u_user',gs.getUserID());

gr1.query();

if(gr1.next()){

data.isLike=false;

gr1.deleteRecord();}

gs.addInfoMessage('Deleted from your favourites');

}

//K17 Updates -Ends

if (input)

data.sys_id = input.sys_id;

else if(options.sys_id)

data.sys_id = options.sys_id;

else

data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');

data._attachmentGUID = gs.generateGUID();

// portal can specify a catalog home page

data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home";

var validatedItem = new GlideappCatalogItem.get(data.sys_id);

if (!validatedItem.canView())

return;

data.sc_cat_item = $sp.getCatalogItem(data.sys_id);

if (data.sc_cat_item.category) {

var categoryGR = new GlideRecord('sc_category');

categoryGR.get(data.sc_cat_item.category);

if(categoryGR.isValidRecord()){

data.category = {

name: categoryGR.getDisplayValue('title'),

url: '?id=k17_sc_category&sys_id=' + categoryGR.sys_id

}

}

}

$sp.logStat('Catalog View', data.sc_cat_item.sys_class_name, data.sys_id, data.sc_cat_item.name);

})()

...................................................................................................................................................................................................

CLient CONTROLLER:

function ($scope, $http, spUtil, nowAttachmentHandler, $rootScope, $sanitize, $window, $sce, i18n) {

var c = this;

c.quantity = 1;

$scope.data.sc_cat_item.description = $sce.trustAsHtml($scope.data.sc_cat_item.description);

c.widget._debugContextMenu = [

[ i18n.getMessage("Open") + " sc_cat_item", function(){

var item = c.data.sc_cat_item;

$window.open("/$sp.do?id=form&table=" + item.table + "&sys_id=" + item.sys_id); }]

];

c.showAddCartBtn = function() {

return c.options.show_add_cart_button &&

c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&

!c.data.sc_cat_item.no_cart;

}

//K17- updates- starts

c.handleFavorites=function(cat_id,col,evt){

c.data.isLike=!col;

// $scope.server.update();

if(col==false){

// console.log("inside col false");

c.server.get({

action: "Insert",

catID: cat_id

}).then(function(response) {

})

}

else if(col==true){

$scope.server.get({

action: "Delete",

catID: cat_id

}).then(function(response) {})

}

}

//K17- updates- ends

c.showQuantitySelector = function() {

return c.data.sc_cat_item.sys_class_name !== "sc_cat_item_producer" &&

!c.data.sc_cat_item.no_quantity;

}

$scope.$on('dialog.upload_too_large.show', function(e){

console.log($scope.m.largeAttachmentMsg);

spUtil.addErrorMessage($scope.m.largeAttachmentMsg);

});

$scope.m = $scope.data.msgs;

$scope.submitButtonMsg = $scope.m.submitMsg;

var ah = $scope.attachmentHandler = new nowAttachmentHandler(setAttachments, function() {});

ah.setParams('sp_portal', $scope.data._attachmentGUID, 1024 * 1024 * 24);

function setAttachments(attachments, action) {

$scope.attachments = attachments;

}

$scope.attachmentHandler.getAttachmentList();

$scope.confirmDeleteAttachment = function(attachment, $event) {

      $rootScope.$broadcast("dialog.delete_attachment.show", {

          parms: {

              ok: function() {

                  $scope.attachmentHandler.deleteAttachment(attachment);

                  $rootScope.$broadcast("dialog.delete_attachment.close");

              },

              cancel: function() {

                  $rootScope.$broadcast("dialog.delete_attachment.close");

              },

              details: attachment.name

          }

      })

  }

// Breadcrumbs

if ($scope.data.sc_cat_item && $scope.data.sc_cat_item.sys_id !='3f1dd0320a0a0b99000a53f7604a2ef9' && $scope.data.sc_cat_item.sys_id !='a7c1cc47131672407a2256022244b0cd') {

var bc = [{label: $scope.page.title, url: '?id=' + $scope.data.sc_catalog_page}];

if ($scope.data.category)

bc[bc.length] = {label: $scope.data.category.name, url: $scope.data.category.url};

bc[bc.length] = {label: $scope.data.sc_cat_item.name, url: '#'};

$rootScope.$broadcast('sp.update.breadcrumbs', bc);

spUtil.setSearchPage('sc');

}else if($scope.data.sc_cat_item.sys_id =='3f1dd0320a0a0b99000a53f7604a2ef9' || $scope.data.sc_cat_item.sys_id =='a7c1cc47131672407a2256022244b0cd'){

var bc1 = [{label: 'K17-Something Broken', url: '?id=' + 'k17_something_broken'}];

$rootScope.$broadcast('sp.update.breadcrumbs', bc1);

}

var g_form;

$scope.$on('spModel.gForm.initialized', function(e, gFormInstance){

g_form = gFormInstance;

// This runs after all onSubmit scripts have executed

g_form.$private.events.on('submitted', function(){

if ($scope.data.sc_cat_item.item_action === "order")

getOne();

else if ($scope.data.sc_cat_item.item_action === "add_to_cart")

addToCart();

});

});

$scope.triggerAddToCart = function() {

$scope.data.sc_cat_item.item_action = "add_to_cart";

$scope.data.sc_cat_item.quantity = c.quantity;

if (g_form)

g_form.submit();

}

$scope.triggerOnSubmit = function(){

$scope.data.sc_cat_item.item_action = "order";

$scope.data.sc_cat_item.quantity = c.quantity;

if (g_form)

g_form.submit();

}

// order / create request

function getOne() {

postCatalogFormRequest().success(function(response) {

var a = response.answer;

var n = a.number;

$scope.$emit("$$uiNotification", response.$$uiNotification);

$scope.$emit("$sp.sc_cat_item.submitted", a);

if (n)

issueMessage(n, a.table, a.sys_id);

$scope.submitting = false;

$scope.submitButtonMsg = $scope.m.submittedMsg;

});

}

function addToCart() {

postCatalogFormRequest().success(function(response) {

$rootScope.$broadcast("$sp.service_catalog.cart.add_item");

$rootScope.$broadcast("$sp.service_catalog.cart.update");

//spUtil.addInfoMessage("Added item to shopping cart");

$scope.submitting = false;

});

}

function postCatalogFormRequest() {

setFieldsReadonly();

$scope.submitted = true;

$scope.submitting = true;

var t = $scope.data.sc_cat_item;

t._attachmentGUID = $scope.data._attachmentGUID;

// calls into SPCatalogForm.getItem()

return $http.post(spUtil.getURL('sc_cat_item'), t);

}

// spModel populates mandatory - hasMandatory is called by the submit button

$scope.hasMandatory = function(mandatory) {

return mandatory && mandatory.length > 0;

};

// switch catalog items

var unregister = $scope.$on('$sp.list.click', onListClick);

$scope.$on("$destroy", function() {

unregister();

});

function onListClick(evt, arg) {

$scope.data.sys_id = arg.sys_id;

spUtil.update($scope);

}

function setFieldsReadonly(){

var allFields = g_form.getFieldNames();

for(var fieldName in allFields){

g_form.setReadOnly(allFields[fieldName], true);

}

}

function issueMessage(n, table, sys_id) {

var page = table == 'sc_request' ? 'sc_request' : 'ticket';

if (c.options.page) {page = c.options.page;}

if (c.options.table) {table = c.options.table;}

var url = spUtil.format(c.options.url, {page: page, table: table, sys_id: sys_id});

if (c.options.auto_redirect == "true") {

$window.location.href = url;

return;

}

var t = $scope.m.createdMsg + " " + n + " - ";

t += $scope.m.trackMsg;

t += ' <a href="' + url + '">' + $scope.m.clickMsg + '</a>';

spUtil.addInfoMessage(t);

}

}

Thanks in Advance..

// populate the 'data' variable with catalog item, variables, and variable view(function() { options.show_add_cart_button = (options.show_add_cart_button == "true");
if (options.page) { var pageGR = new GlideRecord("sp_page"); options.page = (pageGR.get(options.page)) ? pageGR.getValue("id") : null; }
if (options.table) { var tableGR = new GlideRecord("sys_db_object"); options.table = (tableGR.get(options.table)) ? tableGR.getValue("name") : null; }
options.url = options.url || "?id={page}&table={table}&sys_id={sys_id}"; data.showPrices = $sp.showCatalogPrices(); var m = data.msgs = {}; m.submitMsg = gs.getMessage("Submit"); m.submittedMsg = gs.getMessage("Submitted"); m.createdMsg = gs.getMessage("Created"); m.trackMsg = gs.getMessage("track using 'Requests' in the header or"); m.clickMsg = gs.getMessage("click here to view"); m.dialogTitle = gs.getMessage("Delete Attachment"); m.dialogMessage = gs.getMessage("Are you sure?"); m.dialogOK = gs.getMessage("OK"); m.dialogCancel = gs.getMessage("Cancel"); m.largeAttachmentMsg = gs.getMessage("Attached files must be smaller than {0} - please try again", "24MB");

//K17 Updates - Starts data.isLike=false; var gr2 = new GlideRecord('u_favorite_catalog_items'); gr2.addQuery('u_catalog_item',$sp.getParameter('sys_id')); gr2.addQuery('u_user',gs.getUserID()); gr2.query(); if(gr2.next()){     data.isLike=true; } if(input && input.action=="Insert"){ var gr2 = new GlideRecord('u_favorite_catalog_items'); gr2.addQuery('u_catalog_item',input.catID); gr2.addQuery('u_user',gs.getUserID()); gr2.query(); data.isLike=true; if(!gr2.next()){ gr2.u_catalog_item=input.catID; gr2.u_user=gs.getUserID() gr2.update(); } gs.addInfoMessage('Added to your favourites'); }
if(input.action=="Delete"){ var gr1 = new GlideRecord('u_favorite_catalog_items'); gr1.addQuery('u_catalog_item',input.catID); gr1.addQuery('u_user',gs.getUserID()); gr1.query(); if(gr1.next()){ data.isLike=false; gr1.deleteRecord();} gs.addInfoMessage('Deleted from your favourites'); } //K17 Updates -Ends if (input) data.sys_id = input.sys_id; else if(options.sys_id) data.sys_id = options.sys_id; else data.sys_id = $sp.getParameter("sys_id") || $sp.getParameter('sl_sys_id');
data._attachmentGUID = gs.generateGUID(); // portal can specify a catalog home page data.sc_catalog_page = $sp.getDisplayValue("sc_catalog_page") || "sc_home"; var validatedItem = new GlideappCatalogItem.get(data.sys_id); if (!validatedItem.canView()) return;
data.sc_cat_item = $sp.getCatalogItem(data.sys_id); if (data.sc_cat_item.category) { var categoryGR = new GlideRecord('sc_category'); categoryGR.get(data.sc_cat_item.category); if(categoryGR.isValidRecord()){ data.category = { name: categoryGR.getDisplayValue('title'), url: '?id=k17_sc_category&sys_id=' + categoryGR.sys_id } }
}
$sp.logStat('Catalog View', data.sc_cat_item.sys_class_name, data.sys_id, data.sc_cat_item.name);})()

6 REPLIES 6

kulikovvadim
Tera Contributor

Hi,

Try to use "page route maps" (https://docs.servicenow.com/bundle/london-servicenow-platform/page/build/service-portal/task/reroute...) from "request" page to "ticket" page. You will have to modify server script of widgets on this page (ticket) to determine RITM id by Request id.

Something like that:

 

//"Ticket Fields" widget server script example

...
var gr = $sp.getRecord();
var sys_id = $sp.getParameter("sys_id");
var table = $sp.getParameter("table");
if (table == 'sc_request') {
	var item = new GlideRecord('sc_req_item');
	item.addQuery('request',sys_id);
	item.query();
	if (item.next()) {
		gr = item;
	}
}
...

 

Dude! This was extremely helpful!

 

Thank you

Hi TJ

 

Did you get this working? Would you mind sharing your widget scripts?

Hi,

I followed your script and the redirect is working. However, when trying to add comments, it doesn't seem to update the RITM. Do you know why?