Opportunity Mini Page: Set default Currency value based on User

Hi community,

We want to set the default currency in the Opportunity Mini Page (front end event), based on the Org Role of a user (oob functionality is based on the Base Currency system setting).

Is there any code implementation of a similar request ?

Sasori

Like 0

Like

2 comments
Best reply

Hello Sasori!

1) Add MultiCurrencyEditUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["MultiCurrencyEditUtilities"] ...

2) Add MultiCurrencyEditUtilities as a mixing to the minipage schema. Example:

...
mixins: {
  MultiCurrencyEditUtilities: "Terrasoft.MultiCurrencyEditUtilities",
  ...

3) Instead of using roles check you can use operation permission check. To use it you need to add RightUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["RightUtilities"], function(RightUtilities) { ...

4) Use the following methods in your minipage:

...
onEntityInitialized: function() {
  this.callParent(arguments);
  this.checkCurrencyForUser();
},
checkCurrencyForUser: function() {
  RightUtilities.checkCanExecuteOperation({
  operation: "NeedToUseEuro"
}, function(result) {
  if (result) {
    var euroId = "c0057119-53e6-df11-971b-001d60e938c6";
    this.onCurrencyMenuItemClick(euroId);
  }
 }, this);
}
...

The logic above will check if the user has access to the "NeedToUseEuro" operation (or this user role has access to the operation) and if so we will call the onCurrencyMenuItemClick method and pass euroId as an argument (see the onCurrencyMenuItemClick method signature in the MultiCurrencyEditUtilities module).

c0057119-53e6-df11-971b-001d60e938c6 is an Id of the "Euro" currency from the "Currency" table in the database. All you need to do is:

1. Correctly specify operation permissions (check if your user is not in several roles that are used in different operation permissions check)

2. Correctly setup a chain of operation permissions checks in the context of the checkCurrencyForUser method execution

P.S. Article about adding a multi-currency field: 

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/overview#case-1915

Hi community,

Any update ?

Sasori

Hello Sasori!

1) Add MultiCurrencyEditUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["MultiCurrencyEditUtilities"] ...

2) Add MultiCurrencyEditUtilities as a mixing to the minipage schema. Example:

...
mixins: {
  MultiCurrencyEditUtilities: "Terrasoft.MultiCurrencyEditUtilities",
  ...

3) Instead of using roles check you can use operation permission check. To use it you need to add RightUtilities module as a dependency to your minipage schema. Example:

define("OpportunityMiniPage", ["RightUtilities"], function(RightUtilities) { ...

4) Use the following methods in your minipage:

...
onEntityInitialized: function() {
  this.callParent(arguments);
  this.checkCurrencyForUser();
},
checkCurrencyForUser: function() {
  RightUtilities.checkCanExecuteOperation({
  operation: "NeedToUseEuro"
}, function(result) {
  if (result) {
    var euroId = "c0057119-53e6-df11-971b-001d60e938c6";
    this.onCurrencyMenuItemClick(euroId);
  }
 }, this);
}
...

The logic above will check if the user has access to the "NeedToUseEuro" operation (or this user role has access to the operation) and if so we will call the onCurrencyMenuItemClick method and pass euroId as an argument (see the onCurrencyMenuItemClick method signature in the MultiCurrencyEditUtilities module).

c0057119-53e6-df11-971b-001d60e938c6 is an Id of the "Euro" currency from the "Currency" table in the database. All you need to do is:

1. Correctly specify operation permissions (check if your user is not in several roles that are used in different operation permissions check)

2. Correctly setup a chain of operation permissions checks in the context of the checkCurrencyForUser method execution

P.S. Article about adding a multi-currency field: 

https://academy.creatio.com/docs/developer/interface_elements/record_page/field/overview#case-1915

Show all comments