Using the 'ContainsCurrentUser' in the Javascript editor of a Group page

Discussions about Forms Designer for SharePoint 2010.
User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

16 Oct 2015

Code below will work with display pages:

Code: Select all

SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
    var ctx = new SP.ClientContext.get_current(); 
    var web = ctx.get_web(); 
    ctx.load(web); 
    var user = web.get_currentUser(); 
    user.retrieve(); 
    ctx.executeQueryAsync( 
    function () { 
      var dic = [];
  fd.field('Name08').control()._el().find("tr a").each(function() {
dic.push($(this).text());
  });
      var found = false;

      for (var i = 0; i < dic.length; i++) {
        if (dic[i] == user.get_loginName()){
          found = true;
        }
      }
      if (found) {
        $('.Table').show();
      }
      else {
        $('.Table').hide();
      }


    }); 
}), "SP.js");

Merley72
Posts: 17
Joined: Tue Sep 30, 2014

19 Oct 2015

Hi There,

I added the display code in the same fashion and esnured that the field and CSS names were all correct, however I'm not having success yet with the Display side of things. The 'Table' section does not show in the 'Display' mode, but I know it is there because when I open the document, it very briefly flashes onto the screen.

I'm not certain if I need to do anything particular to things, but please advise if I need to alter anything.

Thanks, Alan C.

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

19 Oct 2015

Hello!

Probably your 'Name08' field isn't displaying peoples logins, so try the code below:

Code: Select all

var dic = [];
fd.field('Name08').control()._el().find("tr a").each(function() {
	var id = fd.getUrlParam($(this).attr('href'), 'ID')
	dic.push(id);
});
var found = false;

for (var i = 0; i < dic.length; i++) {
	if (dic[i] == _spPageContextInfo.userId){
	  found = true;
	}
}
if (found) {
	$('.Table').show();
}
else {
	$('.Table').hide();
}

Merley72
Posts: 17
Joined: Tue Sep 30, 2014

19 Oct 2015

Thanks Rostislav - that performs exactly. I've used different people to look at the same document and the sections hide and show as required on the 'Display' version. I was caught out for a couple of minutes when I added a 'Save' button to the display form however soon realised the error!!!! I replaced that with a Close and also a 'Button' as well and both of the display. I am not using a Button at the moment, however can potentially see the possibility if some form of remote step needs to be invoked or if data from the document needs to be extracted and added t a 'new' document etc.

Thanks again for the assistance.

Alan C.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests