- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2020 03:02 AM
Hi,
I have a button and an onclick function defined there. When I click this button I want to redirect to the specific url in the same window. Unfortunately, I get this error even if the function is defined in client script:
Uncaught ReferenceError: redirectToDraft is not defined onclick https://mwtab.service-now.com/kp?id=form_kb&table=kb_knowledge&sys_id=17fffdc3db89ecd0391061bbd3961927:1
. Do you know how to solve this? Thanks in advance.
HTML:
<div class="row center"><button onclick="redirectToDraft()" class="btn btn-warning">Draft
<!--<a href="/kp?id=form&table=kb_knowledge&sys_id={{data.articleSysId}}" class="link_style">Draft</a>-->
</button></div>
Client Script:
function redirectToDraft(){
var url = "/kp?id=form&table=kb_knowledge&sys_id=" + $scope.data.articleSysId;
window.location.href = url;
}
Server side to get articleSysId
//var articleSysId;
var article = new GlideRecord('kb_knowledge');
article.get(input.article);
gs.info('asd' + input.article);
var newRecord = new KBVersioning().checkout(article);
var gr = new GlideRecord('kb_knowledge');
gr.addQuery('number', article.number + '');
gr.orderByDesc('version');
gr.setLimit(1);
gr.query();
if(gr.next()) {
data.articleSysId = gr.sys_id +'';
}
gs.info("sys id" + data.articleSysId);
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2020 03:09 AM
can you try to use ng-click instead of onclick ?
eg:
<div class="row center"><button ng-click="redirectToDraft()" class="btn btn-warning">Draft
<!--<a href="/kp?id=form&table=kb_knowledge&sys_id={{data.articleSysId}}" class="link_style">Draft</a>-->
</button></div>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2020 03:09 AM
can you try to use ng-click instead of onclick ?
eg:
<div class="row center"><button ng-click="redirectToDraft()" class="btn btn-warning">Draft
<!--<a href="/kp?id=form&table=kb_knowledge&sys_id={{data.articleSysId}}" class="link_style">Draft</a>-->
</button></div>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2020 03:39 AM
Tested on my personal instance.
HTML
<div class="buttondiv">
<input id="my_button" class="button" type="button" value="create new Project" ng-click="c.myFunction()">
</div>
Client script:
function ($uibModal, $scope, spUtil) {
var c = this;
c.myFunction = function() {
var url = "/sp?id=form&table=kb_knowledge&sys_id=" + $scope.data.articleSysId;
window.location.href = url;
};
}
Server side script. for testing i have hardcoded one article sys_id. also in url i have added sp portal for testing.
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.articleSysId='c85cd2519f77230088aebde8132e70c2'; // this is for testing
})();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2021 01:15 PM
Let me know if you need any further help here.
If my answer helped you, kindly mark the answer as correct and close this thread.