Custom Widget - $core_v2_widget.ExecuteFile () To Try And Show PrivateEmail field

I'm running into difficulty trying to get a Custom Widget to pull data from $core_v2_user.Get () field PrivateEmail.

The custom widget is shown on the User Profile screen and it's set to only display to the accessing user if they are member of a certain Group ID - this part all works OK.

On the widget I am trying to display the following fields which you can only see through the Administration screen:

  • Username
  • PrivateEmail
  • LastVisitedDate

When I use my own ID (is part of Administrators role), I am seeing all three fields no issue.

When I use a normal user (how should see custom widget based on Group ID), they are seeing Username and LastVistedDate but not PrivateEmail - the only time they see a value in the PrivateEmail is if they are looking at their own profile.

To try and get around this I have thought of using $core_v2_widget.ExecuteFile ()  as you have the options to run RunAsServiceUser = $runAsServiceUserArg or RunAsUserName = $runAsUserNameArg. My thought was to use this and execute my .vm file that has a $core_v2_user.Get () by username as either the service account or my own account, both of which I would assume would see PrivateEmail for all users with no issues.

I have tried both of these and neither are working, as soon I as introduce either RunAsServiceUser or RunAsUserName the PrivateEmail is not found.

Is this possible?

This does not work:

#set($runAsServiceUserArg = true)
$core_v2_widget.ExecuteFile('GetUserAsService.vm', "%{ RunAsServiceUser = $runAsServiceUserArg }"))

This does work - I get data but non admin users cannot see PrivateEmail data:

$core_v2_widget.ExecuteFile('GetUserAsService.vm')

My VM simply contains this:

#set($myResponse = $core_v2_user.Get("%{ Username = $usernameArg }"))

#set($myApiPrivateEmail = $myResponse.PrivateEmail)
#set($myApiUserName = $myResponse.username)
#set($myApiLastVisited = $myResponse.LastVisitedDate)

Then the widget is displaying:

<li class="field-item">
<br />
<span class="field-item-name">$core_v2_language.GetResource("Admin_SSO_Username_Name")</span>
<span class="field-item-description">$myApiUserName</span>
<br />
<li class="field-item">
<span class="field-item-name">$core_v2_language.GetResource("Admin_Email_Address_Name")</span>
<span class="field-item-description">$myApiPrivateEmail</span>
<br />
</li>
<li class="field-item">
<span class="field-item-name">$core_v2_language.GetResource("Admin_Last_Visited_Name")</span>
<span class="field-item-description">$core_v2_language.FormatDate($myApiLastVisited)</span>
<br />
</li>



Just adding in more content.
[edited by: Lee.Taphouse at 12:15 PM (GMT 0) on Wed, Nov 25 2020]
Parents Reply Children
  • - THANKYOU!!  Rending the fields in the VM has worked, so making the call here:

    #if (($roleResponse) || ($memberResponse))

    #if ($readOnly)
    $core_v2_widget.ExecuteFile('GetUserAsService.vm', "%{ RunAsServiceUser = $runAsServiceUserArg }"))

    #else
    ## In Edit mode, do not show.
    #end
    #else

    In the VM I have the fields:

    #set($myResponse = $core_v2_user.Get("%{ Username = $usernameArg }"))

    #set($myApiPrivateEmail = $myResponse.PrivateEmail)
    #set($myApiUserName = $myResponse.username)
    #set($myApiLastVisited = $myResponse.LastVisitedDate)

    <fieldset>
    <span class="field-item-description">$core_v2_language.GetResource("Amin_Only_Info_Description")</span>
    <ul class="field-list">
    <li class="field-item">
    <br />
    <span class="field-item-name">$core_v2_language.GetResource("Admin_SSO_Username_Name")</span>
    <span class="field-item-description">$myApiUserName</span>
    <br />
    </li>

    Now it is working I will clean it up Wink