Button functionality to create a record on request table from custom portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 10:20 PM - edited ‎09-23-2024 10:52 PM
Hi
I've created a button on a custom portal and I want to create an approval request from that button is there any way through which i can do this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 10:57 PM
Hi Amrit,
You can try out these:
1. HTML: <button class="btn btn-primary" ng-click="c.createApproval()">Request Approval</button>
2. Client:
function($scope, $http, spModal) {
$scope.createApproval = function() {
var requestData = {
'sys_id': $scope.data.recordSysId,
'approval_type': 'user'
};
$http.post('/api/now/table/your_table_name_here', requestData)
.then(function(response) {
spModal.alert('Approval request created successfully.');
});
};}
3. Server:
(function() {
var approvalGr = new GlideRecord('sysapproval_approver');
approvalGr.initialize();
approvalGr.setValue('source_table', 'your_table_name'); // add your tables
approvalGr.setValue('source', input.sys_id);
approvalGr.setValue('approver', 'user_id_here');
approvalGr.insert();
data.result = "Approval created";
})();
Few adjustments are required based on your requirement like using group approval incase instead of user. Adding server side approvers dynamically instead as show above etc. But this is basic format you can start with.
Happy learning!
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.