1

Is there a way to hide certain column from DispForm based on if the current user is part of a Security Group? Unfortunately, the security group contains Active Directory group not individual names thats why I was hoping target audience would work.

Here's what I've done so far:

In DispForm.aspx, added a content editor web part linked to a txt file with

<div id="hidValue"></div>

Added a target audience in the CEWP.

In SharePoint Designer, I edited the custom DispForm.aspx and added the following

<xsl:variable name="varInfo" select="@AdditionalInfo"/>
<script language="javascript">
    var i =<xsl:value-of select="$varInfo"/>;
    alert('<xsl:value-of select="$varInfo"/>');
</script>

The alert works but when I attempted to populate the <div id="hidValue"></div> with any of below lines, none of them worked:

document.getElementById("hidValue").innerHTML = '<xsl:value-of select="$varInfo"/>';
document.getElementById("hidValue").innerHTML = {$varInfo};

Basically, I want the value of @AdditionalInfo hidden to all except for the target audience.

I also tried below code which identifies the current user's group but does not work if user is part of an AD group inside the SharePoint group:

var ckUserGrp = _spPageContextInfo.webAbsoluteUrl +'/_api/web/currentuser/groups'
$.getJSON(ckUserGrp, function (data) {
$.each(data.value, function (key, value) {
    var grpName = value.Title;
    console.log(grpName);
});
})
2
  • For How many groups you want to show this field? Commented Jan 24, 2019 at 7:49
  • At the moment, the demand is just for one SharePoint group Commented Jan 24, 2019 at 17:10

1 Answer 1

1

I figured this out by switching the Content Editor to Script Editor web part with the following code in custom DispForm:

<div class="hidInfo" id="varInfo"><xsl:value-of select="@AdditionalInfo" disable-output-escaping="yes"/></div>

<script language="javascript">
     var i = document.getElementById("varInfo").innerHTML;
     document.getElementById("hidValue").innerHTML = i;
</script>

Then added a css to hide the additional info

.hidInfo {
    display: none;
}

Seems to work so far with limited testing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.