- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
We need to introduce withdraw case button as below:
As of now button is visible but on click of button page is redirecting to undefined.
Ideally on click of button, subsequent case should be cancelled and its approvals should be no longer required without affecting any case state and its approvals.
Technical details:
widget - Request Ticket Action
html - <div>
<button name="withdraw" ng-disabled="c.withdraw" ng-click="c.redirectTowithdraw()" class="btn btn-primary btn-block ng-binding ng-scope">
Withdraw Request
</button>
</div>
server script:
This is somehow not working, please help if i am missing something?
Thanks,
Sri
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Sri,
The redirect to undefined is happening because your server call is not returning a URL.
In the widget client script you do this:
top.window.location = r.data.resubmit_url;
But in your Script Include, setWithdrawReq() does not return anything because the return URL is commented out. So r.data.resubmit_url becomes undefined.
There are also a few script issues to fix:
- new xxxxUtils.setWithdrawReq(recordGr) is not the right way to call a Script Include method.
- var sysID = xxxx.sys_id uses xxxx, but that variable is not defined.
- addEncodedQuery('sys_id', sysID) is not valid usage. Use addQuery('sys_id', sysID) or build one encoded query string.
- if (grAppTask.next()) updates only one approval. Use while (grAppTask.next()) if there can be multiple approvals.
- cs.update() should be inside the block where the case record is actually found/changed.
A cleaner server script pattern would be:
(function() {
var tableName = $sp.getParameter('table');
var recordId = $sp.getParameter('sys_id'); if (input && input.withdraw && tableName && recordId) {
var recordGr = new GlideRecord(tableName); if (recordGr.get(recordId)) {
var util = new PANFUtils();
data.resubmit_url = util.setWithdrawReq(recordGr);
}
}
})();And your Script Include method should return something:
setWithdrawReq: function(caseGr) {
var sysID = caseGr.getUniqueValue(); var cs = new GlideRecord('xxxx_table');
if (!cs.get(sysID))
return '?id=my_requests'; var approvals = new GlideRecord('sysapproval_approver');
approvals.addQuery('sysapproval', cs.getUniqueValue());
approvals.addQuery('state', 'requested');
approvals.query(); while (approvals.next()) {
approvals.state = 'not_required';
approvals.comments = 'Case was withdrawn by requester.';
approvals.update();
}cs.state = 7; // confirm this is the correct cancelled/withdrawn state for your table
cs.approval = 'rejected'; // confirm this is really desired
cs.comments = 'Case was withdrawn by requester.';
cs.update();
return '?id=my_requests'; }
Then in the client script, guard the redirect:
c.redirectTowithdraw = function() {
c.withdraw = true; c.server.get({ withdraw: true }).then(function(r) {
if (r.data && r.data.resubmit_url) {
top.window.location = r.data.resubmit_url;
} else {
c.withdraw = false;
spUtil.addErrorMessage('Unable to withdraw the request. Please contact support.');
}
});
};One more important point: your text says the case should be cancelled and approvals should become no longer required, but also says “without affecting case state and approvals.” Those are conflicting requirements. If the business requirement is “withdraw,” then changing the case state and approval records is expected. If the requirement is only to hide/disable the button, then you should not update the case/approval records.
So the immediate fix is: return a URL from the Script Include and call the Script Include correctly. After that, validate the business rule for whether state = 7 and approval = rejected are really the correct values for your custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You're mixing AngularJS and native HTML/JS interaction.
From a user experience, what's the reason for redirecting? That can be an annoying experience and likely not preferred
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Sri,
The redirect to undefined is happening because your server call is not returning a URL.
In the widget client script you do this:
top.window.location = r.data.resubmit_url;
But in your Script Include, setWithdrawReq() does not return anything because the return URL is commented out. So r.data.resubmit_url becomes undefined.
There are also a few script issues to fix:
- new xxxxUtils.setWithdrawReq(recordGr) is not the right way to call a Script Include method.
- var sysID = xxxx.sys_id uses xxxx, but that variable is not defined.
- addEncodedQuery('sys_id', sysID) is not valid usage. Use addQuery('sys_id', sysID) or build one encoded query string.
- if (grAppTask.next()) updates only one approval. Use while (grAppTask.next()) if there can be multiple approvals.
- cs.update() should be inside the block where the case record is actually found/changed.
A cleaner server script pattern would be:
(function() {
var tableName = $sp.getParameter('table');
var recordId = $sp.getParameter('sys_id'); if (input && input.withdraw && tableName && recordId) {
var recordGr = new GlideRecord(tableName); if (recordGr.get(recordId)) {
var util = new PANFUtils();
data.resubmit_url = util.setWithdrawReq(recordGr);
}
}
})();And your Script Include method should return something:
setWithdrawReq: function(caseGr) {
var sysID = caseGr.getUniqueValue(); var cs = new GlideRecord('xxxx_table');
if (!cs.get(sysID))
return '?id=my_requests'; var approvals = new GlideRecord('sysapproval_approver');
approvals.addQuery('sysapproval', cs.getUniqueValue());
approvals.addQuery('state', 'requested');
approvals.query(); while (approvals.next()) {
approvals.state = 'not_required';
approvals.comments = 'Case was withdrawn by requester.';
approvals.update();
}cs.state = 7; // confirm this is the correct cancelled/withdrawn state for your table
cs.approval = 'rejected'; // confirm this is really desired
cs.comments = 'Case was withdrawn by requester.';
cs.update();
return '?id=my_requests'; }
Then in the client script, guard the redirect:
c.redirectTowithdraw = function() {
c.withdraw = true; c.server.get({ withdraw: true }).then(function(r) {
if (r.data && r.data.resubmit_url) {
top.window.location = r.data.resubmit_url;
} else {
c.withdraw = false;
spUtil.addErrorMessage('Unable to withdraw the request. Please contact support.');
}
});
};One more important point: your text says the case should be cancelled and approvals should become no longer required, but also says “without affecting case state and approvals.” Those are conflicting requirements. If the business requirement is “withdraw,” then changing the case state and approval records is expected. If the requirement is only to hide/disable the button, then you should not update the case/approval records.
So the immediate fix is: return a URL from the Script Include and call the Script Include correctly. After that, validate the business rule for whether state = 7 and approval = rejected are really the correct values for your custom table.