Button functionality to create a record on request table from custom portal

tyagi_amrit2701
Tera Contributor

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?

1 REPLY 1

Akash4
Kilo Sage
Kilo Sage

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!

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.