Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Custom Macro Access UserSettings View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
ian-inkdigitalagency - 5/31/2013 7:24:47 AM
   
Custom Macro Access UserSettings
I have created a custom macro that accepts (int UserID, string RoleName)
Returns a bool.

I want to use this macro on the visibility property of a Custom Field on the System.UserSettings table. This should show/hide fields on the Custom Fields tab in CMSAdmin User Management


The macro is registered correctly and I can debug it in visual studio. I am calling the macro in the visibility property like this...

UserIsInRole( UserSettingsUserID, "SomeRoleName")

I want the custom field in User settings to show/hide in the Custom Field tab in User Admin.

What ever I try the value of UserSettingsUserID = 0, I tried UserSettingsUserID.Value too!

Does anyone know what I am doing wrong?


Thanks for you help! It's driving me mad!

Ian

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/31/2013 10:28:43 AM
   
RE:Custom Macro Access UserSettings
Just to clarify you are in Site Manager>Administraton>Users>select user>Custom Fields tab?

If you're setting visibility in the code behind on that custom fields page, you can simply use this code:
UserInfo ui = (UserInfo)EditedObject;
ui.IsInRole("roleName", "siteName");
If you're using it somewhere else, there is already a macro that will do this by using
CurrentUser.IsInRole("roleName", true)
I know the latter doesn't help with getting a selected user. You may want to post your macro code and registration to ensure it is correct.

User avatar
Member
Member
kentico-inkdigitalagency - 5/31/2013 11:13:01 AM
   
RE:Custom Macro Access UserSettings
Hi FroggyEye,

Thanks for your suggestions.

Yes I want to show/hide certain custom fields from the Site Manager>Administration>Users>select user>Custom Fields tab based on the selected users role.

I was hoping to achieve this using a macro in the visibility field property under..
Site Manager > Development > System Tables > Edit User - Settings > Select Field > Set Visibility Property = UserIsInRole(UserSettingsUserID, "Student")

My macro just accepts two parameters an int and string. When I debug the macro the UserSettingsUserID is always 0.


Editing the custom fields tab code seems a bit to hard coded for what I want to achieve. I just want different custom fields displayed depending on the role the user is in.

Can you you think of an easier way to achieve this?

cheers

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/31/2013 1:56:21 PM
   
RE:Custom Macro Access UserSettings
Ok, thats helpful. So you aren't looking for the current user. Have you tried using UserSettingsUserID.Value? You might also need to do some type checking as well in your macro.

User avatar
Certified Developer v7
Certified  Developer v7
ian-inkdigitalagency - 6/3/2013 4:37:16 AM
   
RE:Custom Macro Access UserSettings
Hi FroggyEye,

Thanks for your suggestion of using the EditedObject property!

Got it working using...
MacroName(EditedObject.GetValue("UserSettingsUserID"), "RoleName")

Great start to a sunny Monday morning! YAY

Cheers
Ian