The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Redirect from a Script Includes?

Sandy7
Tera Expert

Hi,

I have a script includes that calls a UI action.

The script includes and UI action together create a knowledge article.

Once the article is created, I would like the knowledge article to be created. Instead, it's just reloading the form of the page i'm on. I'd also like a message that says 'knowledge article created".. 

Can anyone help with this redirect?

 

This is the Script Includes:

var CreateKB = Class.create();
CreateKB.prototype = Object.extendsObject(AbstractAjaxProcessor, {

createkb_from_story: function(){


var surveyId = this.getParameter('sysparm_storyId');

var kbtext = '';
var kbshort_description = '';
var gr = new GlideRecord('rm_story');
gr.addQuery('sys_id','IN', surveyId);
gr.query();
while(gr.next())
{



var link = '<a href="/rm_story.do?sys_id=' + gr.sys_id + '&table=' + gr.getRecordClassName() + gr.number + '</a>';



kbshort_description = gr.sprint.getDisplayValue();


kbtext = kbtext +link+'<br /> '+gr.short_description +'<br/><hr/>';



}

var kbart = new GlideRecord('kb_knowledge');
kbart.initialize();
kbart.short_description = 'Stories deployed in ' + kbshort_description;
kbart.kb_knowledge_base = 'ea3facf9db90f3441d194cd239961978';
kbart.topic = 'News';
kbart.text = kbtext;
kbSysId = kbart.insert();



},


type: 'CreateKB'


}


);

1 ACCEPTED SOLUTION

You can create a URL of created KB article and pass that url to:

gs.setRedirect("pass created URL");

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_GS-setRedirect_O

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

 

Thank you,
Abhishek Gardade

View solution in original post

3 REPLIES 3

AbhishekGardade
Giga Sage

Hello sandy,

Add below line in your code:

kbSysId = kbart.insert();

action.openGlideRecord(kbSysId);

 

Note:

action.setRedirectURL ( 'http://www.mysite.com/mypage.htm' ) ;

 
To direct a user to a record, use this syntax, where new_record is the variable name for the GlideRecord:
action.setRedirectURL (new_record ) ;

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Hi, Thanks for the response. I added the line in bold, and it still is not opening / redirecting to the knowledge article created. Any other suggestions?
Thank you!

You can create a URL of created KB article and pass that url to:

gs.setRedirect("pass created URL");

https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_GS-setRedirect_O

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

 

Thank you,
Abhishek Gardade