cancel
Showing results for 
Search instead for 
Did you mean: 

Cloud Application Studio UI Designer - Script refer current user

former_member656863
Participant
0 Kudos
2,024

Hi,

My client requires to make a field (APS_Status) ReadOnly when it has the value "RA" for all users except Admins.

How can I get to current user data in my script, to condition my calculation to all users, except Admins ?

Is there something like $data.CurrentUser.BusinessRole == "Admin" ?

Thank you for any help provided 🙂

Accepted Solutions (1)

Accepted Solutions (1)

benjaminlatusek
Explorer
0 Kudos

Hello Virak,

I think there are several ways to achieve your request.
You can surely can control the ReadOnly property with the Key-User-Tools as Saurabh Kabra mentioned.

If you like to change the behavior of a SAP field within a SAP screen and need to do it in the Cloud Application Studio you can create an "UI Switch" within your solution and set the property with the extensibility explorer.
https://answers.sap.com/questions/627313/how-to-assign-a-ui-switch-a-ui-element-is-sap-c4c.html

If you're using a custom screen, I would suggest to create a reuse function which is frontend enabled and has a return value specified as indicator. You can call this reuse function in your screen designer into a dedicated field and bind this to your "ReadOnly" property of the regarding field.

The coding of this reuse function should look something like this:

import ABSL;
import BASIS.Global;

var result : DataType::Indicator;
if(Context.GetCurrentUserUISwitches().Where(n=>n == "SS_GOSHOPPING_DISABLE").Count() > 0){
	result = true;
}else{
	result = false;
}
return result;

Please take care of choosing a flat return value. Values with a structure (those which have .content) won't work as far i know.

After you completed your changes on the UI and your coding is finished, you can assign the UI Switch to your user role in the administration / application and user management work-center. Just open your role and open the "UI Switches" Tab. You can assign your newly created UI Switch to the user role.

This should work with Business ByDesign and Cloud4Customer / C/4 Sales & Service

I hope it helps you.
Take care and stay save.

Best regards

Benjamin

former_member656863
Participant
0 Kudos

ALRIGHT it worked!

Thank you so much! I had to understand how to create UI Switches as well and which type and parameters to add to create the Reusable function, but everything's working just like I want now 🙂

Answers (2)

Answers (2)

former_member226
Employee
Employee
0 Kudos

Hi,

In addition to what Cian said, you also achieve the same without using PDI. You can just simply create a new UI Rule with the following logic:

AND(Root.ZCode == "RA", NOT(CONTAINS('ADMIN', MYUSERROLES())), true )

This rule can then be associated with the rule's "Read Only" property as shown.

rule.png

Check this: https://enable.cx.sap.com/media/1_iitw93sw?st=127800 to know about how to create a UI rule and associated it with a property.

former_member656863
Participant
0 Kudos

The UI rule would only be applicable on Standard fields, or KUT extension fields, here my field (APS_Status) has been created through Cloud Application Studio and the screen I am using it in is a EC bound to Customer BO (via .xbo).

So this recommendation is not applicable.

Thank you for the hint though.

former_member226
Employee
Employee
0 Kudos

Hello,

Even if it is a PDI field you can still make use of this in UI Rule with a little trick as shown:

1. Create a PDI field

sdk-field-defined.png

2. Add the same PDI field to UI designer. If not needed then please mark it as HIDDEN but it is very important to add this to the UI designer. This will make sure that your PDI field is part of UI Data Model.

ui-designer.png

3. Now after activation of UI navigate to "Data Model" UI designer and find the "Data Field" generate as part of screen activation.

Copy the full path as this will be needed when creating a new UI rule.

4. Now go to UI rule and simply paste the full path of the Ext field as shown.

Note: This field will not be visible in the left-hand side column of the available field names. However, since you added it to the UI data model (In step 2) hence it can be referenced for that specific UI.

Thanks

EDIT: Due to some reason I am not allowed to add more than 2 images in the same comment, hence please check my next comment for other images.

former_member226
Employee
Employee
former_member656863
Participant
0 Kudos

Hi to both of you 🙂

Thank you for your time, it's much appreciated!

Alright, I have set a UI Rule (Status_RA_Admin) as shown in attached screen ui-rule.png (ui-rule.png).

But then I can't assign this rule to my ext field APS_Status (Feu) as I don't have the option (see screens Status 1 and 2) (status-1.png ).

Usually, at the screen (status-2.png) I should have the option to Perzonalize, Hide, Set as Mandatory, Set as Read-Only, etc. right ?

Therefore, I can't assign the UI Rule to my field APS_Status (Feu)

Have I followed your recommendations well so far? or am I missing a thing?

former_member656863
Participant
former_member226
Employee
Employee
0 Kudos

yes you are correct but I have no clue why properties like Read-Only or Mandatory are not visible 😞 I would suggest you to open a ticket to SAP

cianbarrett
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Virak,

Yes this is very much possible. Try Context.GetAssignedBusinessRoles(); (or Context.GetCurrentIdentityUUID(); if you want to allow for a specific user). You can find out more details on the user by making use the packages AP.PC.IdentityManagement.Global and AP.FO.BusinessPartner.Global.

Hope this helps!

- Cian

former_member656863
Participant
0 Kudos

Well this code would be used in an EventAfterModify or any event script created on the Cloud Application Studio part.

I was actually looking for the code to use in scripting on the UI Designer part, as shown in the screenshot attached.

Thank you for the hint though.