Auth0 Angular 10
Apex Designer Documentation
What's New
Getting Started
Projects
Business Objects
Processes
User Interfaces
App Behaviors
Files
Dependencies
Project Settings
Libraries
Patterns and Best Practices
App Showcase
Angular 10 Base Library
Frequently Asked Questions

Using Options in Business Object Behaviors

Use options to access contextual information

Blank Profile Image
Written by Ashish Gupta
Updated 2 years ago
Less than a minute read

The options parameter is used to pass context through a series of calls in a request.

Accessing the Current User

In a business object behavior, sometimes you may need to capture the user id or email for creating or updating data and populating its createBy or modifiedBy attributes. You can get the user information like this:

let user = options.request.appUser;

let email = user.email;
//do something with the email

let userId = user.id;
//do something with the user id

Specialized Response Handling

If you need users to download an image, you can add it to the options.response like this:

let contentImage = await ContentImage.findOne({ where: { name: imageName } }, options);

if (contentImage.id) {
	options.response.writeHead(200, {
		'Content-Type': contentImage.type,
		'Cache-Control': 'max-age=315360000'
	});

	options.response.end(Buffer.from(contentImage.base64Content, 'base64'));
} else {
	options.response.status(404).send('Not Found');
}

Passing Information from Before Delete to After Delete

In some cases you want to take an action, like notify slack, after delete occurs. The problem with doing that is that after the delete, the data no longer exists to include in the notification. You can temporarily save the required data in options like this in the Before Delete Business Object Behavior:

//Before Delete/Update
options.stashed = {
	name: instance.name
};

Then in the After Delete Business Object Behavior, you can perform the required action:

//After Delete/Update
//notify slack with options.stashed;
postSlackNotification(options.stashed.name);

 

Powered by Apex Designer
Terms of ServicePrivacy Policy
© 2017-2024 Apex Process Consultants