Redirect Submit to RITM instead request on Service Portal

BenG
Tera Guru

Hi,

When I "Submit" a Service catalog item on service Portal, the request page (sc_request) opens.

I would like a rediction of this submit to ritm page instead sc_request page.

I know I have to modifiy the clone of the widget "SC Catalog Item" but I don't know how.

Any idea ?

Thanks for your help,

1 ACCEPTED SOLUTION

oharel
Kilo Sage

Hi there,

I am not sure it is relevant for you anymore, but still, in case someone else needs it, this is what worked for me:

1. Clone the SC Catalog Item widget

2. change the client script:

(look for "$location.search('id=sc_request&is_new_order..." around line 510)

 

//$location.search('id=sc_request&is_new_order=true&table=sc_request&sys_id=' + a.sys_id); //--> we do not want to redirect to the sc_request page
c.data.myrequest = a.sys_id;
c.server.update();
setTimeout(function(){
var ritmid = c.data.ritmId;
								$location.search('id=form&table=sc_req_item&view=ess&sys_id=' + ritmid);
}, 400);
}

3. and in the server script, arounbd line 11, right after return;, add

if(input) {
if(input.myrequest != undefined) {
   var ritm = new GlideRecord('sc_req_item');
   ritm.addQuery('request',input.myrequest); //from line 514 in the client script ritm.query();
//If exactly one RITM is returned, pass to the Client Controller to redirect user
  if(ritm.next()) {
	data.ritmId = ritm.getUniqueValue();
 }
}

That's it.

harel

 

View solution in original post

19 REPLIES 19

Yes, almost a year ago. Naturally it is there or it wouldn't work 🙂

Still a good point if anyone wants to use the code.

Rahul113
Giga Contributor

HI oharel & Aviram,

 

I tried using using this code, But the sys_id is getting undefined.

&view=sp&sys_id=undefined 

I have since then changed the solution.

Removed the server script I added.

In the client script at around line 511, I changed the code:

} else if (!$scope._atf) {
//$location.search('id=sc_request&is_new_order=true&table=sc_request&sys_id=' + a.sys_id); //--> we do not want to redirect to the sc_request page
$location.search('/sp?&newticket=true&table=sc_request&sys_id=' + a.sys_id);// --> direct to homepage and add &newticket=true
c.data.myrequest = a.sys_id;
c.server.update();

removed this part from the client script:

/*setTimeout(function(){
var ritmid = c.data.ritmId;
$location.search('id=form&table=sc_req_item&is_new_order=true&view=ess&sys_id=' + ritmid);
}, 3000);

*/

On the homepage, added a small widget with the following code:

(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if($sp.getParameter("newticket") == 'true'){
gs.addInfoMessage('Thank you for submitting ' + TicketReferral() +'. Notifications regarding its progress will be sent to your email.' );
}

function TicketReferral() {
var myurl;
if($sp.getParameter("table") == 'sc_request'){
var ri = new GlideRecord('sc_req_item');
ri.addQuery('request', $sp.getParameter("sys_id"));
ri.query();
if(ri.next()) {
myurl = '<a href=/sp?view=ess&id=form&table=sc_req_item&sys_id='+ ri.sys_id + '">' + ri.number + '</a>';
return myurl;
}
}

//you can add more ifs here
}
})();

 

You can use the widget to do other things as well, as it does not have any HTML, it is "invisible".

Hope it helps.

Hi Oharel,

Thank you for your help on this. but can you suggest instead of redirecting to homepage i would like it to be redirected to 'id=ticket&table=sc_req_item&view=ess&sys_id=' +ritmid. But the sysid is getting undefined on client although on Serverside i am able to get sysid of the RITM. not sure what i am missing here, any help on this is appreciated.

Hi Oharel,

I am trying to implement this solution however I am running into issues. What is the homepage? Is that a new widget that I should write like the one you have here? Kindly advise please.

Thanks,

Johannes