Is there an inbuilt webservice available to find the roles that the current user belongs to?
Is there an out of the box web service in Creatio that could be used to find all the roles that a user belongs to? Or to check if the user belongs to a particular role? Where can I find the documentation on all the inbuilt webservices provided by Creatio?
Like
Just verified, this is working for me. This is a sample for the account page to disable the account Type if it is "Customer".
Add an attribute to the viewModelConfigDiff:
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[ { "operation": "merge", "path": [ "attributes" ], "values": { "IsTypeEnabled": { value: true } } } ]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
Then, I added a change request handler to listen for values in the Type attribute (which also triggers when the page is initially populated, which is when request.silent==true):
handlers: /**SCHEMA_HANDLERS*/[ { request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { if (request.attributeName === "Type") { request.$context.IsTypeEnabled = (!request.value || request.value.displayValue !== "Customer"); if (!request.silent) { console.log("Type changed", request.oldValue, request.value); } } return next?.handle(request); } } ]/**SCHEMA_HANDLERS*/,
Now, I wire up my attribute to the Type in the viewConfigDiff:
{ "operation": "merge", "name": "Type", "values": { "readonly": "$IsTypeEnabled | crt.InvertBooleanValue" } }
Note, i am using a converter to invert the value since my attribute indicates it's enabled, but the property expects the inverse.
With this in place, if I open an Account with Type=Customer, or change the Type to Customer it is disabled/readonly.
One thing to note, many controls have both a readonly and a disabled property, not sure what the difference is, both seem to work for me, but the readonly seems to be the one that gives the control the visual lock icon. The disabled property also disables the control, but you don't get the lock icon for the control.
Ryan
Basically, you'll query SysUserInRole where the current user = the SysUser value. The SysRole lookup column will provide you the roles linked to this user.
See here: https://customerfx.com/article/determining-if-a-user-has-a-specific-role-in-bpmonline/
For a Freedom UI approach, see https://customerfx.com/article/showing-or-hiding-a-field-if-the-current-user-is-a-member-of-a-role-in-a-creatio-freedom-ui-page/
Ryan
Thanks Ryan. Is there a way to use a webservice for this requirement? Are there any out-of-the-box Webservices that can be called to check if the current user belongs a particular Role using Freedom UI approach ?
If this will be consumed from within Creatio on a Freedom UI page, it's just as easy to do a model query from the Freedom UI page (as shown in the article) as it is to call a web service. Maybe I am missing what you're trying to do? Calling a web service wouldn't really be any different than doing what is suggested in the article using a model query. You could wrap that up as a server-side C# code and expose as a web service, but ultimately, the Freedom UI page is going to request something, whether the web service or the model query, so you could just skip the web service IMO and use the model query.
Thanks Ryan. Yes I agree. Its just that I wanted to explore using webservices in Creatio and also resuse this webservice across projects and am in the process of creating a C# webservice to achieve this.
Ryan Farley,
On a related note, this approach works fine for hiding or showing the fields based on a condition. But is there a way to make it readonly (disabled) based on a condition? I noticed that the "visible" property can be set using a boolean variable like $flag, but this doesnt seem to have any effect with the "readonly" properties of the Text box and Combo box. Is this a known issue and is there a workaround?
Ajay Varghese,
I believe I've been able to bind the readonly property to an attribute and set it programmatically with success (but don't have a system at the moment to verify)
Ajay Varghese,
I'm not sure of an OOTB service for that (roles and user roles). There might be, but it would be a simple service to create. The service would perform the ESQ similar to what is in the articles.
Ajay Varghese,
Additionally, I often wrap that sort of reusable stuff in a client schema class or module so it's easily reusable. Then, whether the class performs a model query or calls a service is irrelevant since it's still abstracted from what is calling it on pages.
Ryan
Ryan Farley,
Yes, thanks for that direction. I have managed to create the webservices using that approach and it works fine. I am a bit surprised that setting that webservice output flag to the readonly property of a textbox and combobox doesnt have any impact while if I use it on the "visible" property then it works fine.
Will wait for your response once you get access to your machine.
Just verified, this is working for me. This is a sample for the account page to disable the account Type if it is "Customer".
Add an attribute to the viewModelConfigDiff:
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[ { "operation": "merge", "path": [ "attributes" ], "values": { "IsTypeEnabled": { value: true } } } ]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
Then, I added a change request handler to listen for values in the Type attribute (which also triggers when the page is initially populated, which is when request.silent==true):
handlers: /**SCHEMA_HANDLERS*/[ { request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { if (request.attributeName === "Type") { request.$context.IsTypeEnabled = (!request.value || request.value.displayValue !== "Customer"); if (!request.silent) { console.log("Type changed", request.oldValue, request.value); } } return next?.handle(request); } } ]/**SCHEMA_HANDLERS*/,
Now, I wire up my attribute to the Type in the viewConfigDiff:
{ "operation": "merge", "name": "Type", "values": { "readonly": "$IsTypeEnabled | crt.InvertBooleanValue" } }
Note, i am using a converter to invert the value since my attribute indicates it's enabled, but the property expects the inverse.
With this in place, if I open an Account with Type=Customer, or change the Type to Customer it is disabled/readonly.
One thing to note, many controls have both a readonly and a disabled property, not sure what the difference is, both seem to work for me, but the readonly seems to be the one that gives the control the visual lock icon. The disabled property also disables the control, but you don't get the lock icon for the control.
Ryan
Ryan Farley,
Thanks Ryan, this worked fine for me. I guess I defined the flag outside of the ViewModelConfigDiff section and hence for some reason whike it worked with the visible property but it consistently failed with the readonly property.
Ryan Farley,
Just a clarification, does HandleViewModelAttributeChangeRequest trigger on both inital page load as well, in addition to any changes to the page?
Ajay Varghese,
Yes it does. When the page initially loads the data for the record, the change event is triggered at that time for each attribute loaded. Meaning, when the data is loaded and bound it will trigger this change (since it is changing the attributes from empty/nothing to a value). It also triggers this request when the user changes values on the page. The request has a silent property. When true (meaning it was a silent change), that means the change was triggered by the system loading the value and NOT by some action performed by the user. If silent=false, that means the user caused the change. If you only want to trigger on a change made by the user, include !request.silent, for example:
if (request.attributeName === "Type" && !request.silent) { // Type was changed by the user }
Ryan