An approval allows you to send a request to one or multiple approvers through a channel. Approvers can review information associated with the approval and accept or reject the approval. You will receive response results from each approver. The approval-related APIs are described below.

Create an Approval

The following example shows how to create an approval named NewApproval.

var properties = []; var approvers = [ {"userIdentifier":"ff80808159b397af0159bbb8ff520009"}, {"userIdentifier":"ff8080815a073050015a147cc7ef000b"} ]; properties.push(new Max.ApprovalProperty({ name: "item value", value: 100, // "0.00" or "field value" type: "NUMBER" // or "AMOUNT" or "STRING" })); // create an approval var approval = new Max.Approval({ title: "NewApproval", description: "The approval desc...", properties: properties, approvers: approvers, mode: "ANY_ORDER" // or "SEQUENTIAL" }); Max.Channel.create({ name: new Date().getTime(), summary: 'MMXApproval', isPublic: false, publishPermissions: 'subscribers', subscribers: approvers }).success(function(ownedChannel) { // create and publish approval to the preApproval channel and owned channel, if they exist approval.publish(channel, ownedChannel).success(function() { // some code on success }).error(function(e) { // some code on error }).always(function() { // some code on any response }); }).error(function(e) { // some code on error });

Listen for Incoming Approval Request or Response

The approval creator and other approvers can listen for an incoming request or approval response. Both requests and responses contain an approvalID that we can use to get the approval object from the server.

// register a listener to listen for new approvals or approval answers and update approval list var listener = new Max.EventListener('receivedMessageListener', function(mmxMessage) { var approvalId = typedPayload.objectId; Max.Approval.get(approvalId).success(function(approval) { // receive approval updates }); }); Max.registerListener(listener);

Get Approvals Using approvalID

Get the approval object from the server using the approvalId.

var approvalId = "someApprovalId"; Max.Approval.get(approvalId).success(function(approval) { // do something with approval object }).error(function(e) { // some code on error });

Fetch Approvals from Server

The following code fetches the assigned approval objects from the server.

var searchFilter = ""; var createdFilter = "APPROVED"; // Status of the approvalcreated by me, which includes APPROVED, DELETED, PENDING, REJECTED, RESUBMITTED, CANCELED var assignedFilter = "PENDING"; // Status of the approval created by others, which includes APPROVED, DELETED, PENDING, REJECTED, RESUBMITTED, CANCELED var offset = 0; Max.Approval.findApprovals(searchFilter, createdFilter, assignedFilter, 10, offset).success(function (approvals) { // here code on get approvals successfully }).error(function (err) { // here code on error }).always(function () { // here code on any answer });

Approval Object Information Display

The approval object contains all the information needed to display in your user interface.

var name = // A user-friendly name of the approval. var details = myApproval.details // The details information of the approval. var status = myApproval.status // Status of the approval, which includes APPROVED, DELETED, PENDING, REJECTED, RESUBMITTED, CANCELED var approvers = myApproval.approvers // approvers objects for the approval var extras = myApproval.extras // A user-defined object used to store arbitrary data will can accessed from the approval instance. var updatedDate = myApproval.updatedDate // Latest updated date of the approval

Accept or Reject Approval Request

Approvers can either accept or reject an approval request, as shown below:

var myApproval; // To accept the approval myApproval.approve().success(function() { // accept approval successfully }).error(function (err) { // here code on error }); // To reject the approval myApproval.reject().success(function() { // reject approval successfully }).error(function (err) { // here code on error });

Delete an Approval

The approval owner can also cancel the approval.

var myApproval; // To delete the approval myApproval.delete().success(function() { // deleted approval successfully }).error(function (err) { // here code on error });