Javascript to display the lists items if the value in Assign To field matched with currently logged in user.

Hi,

Could you please share JavaScript to display the list items if the corresponding Assign To / drop down field (which contains user name) value is equal to logged in user ?

T

July 27th, 2015 12:06am

Hope this may helps you

Filter by Current User

Free Windows Admin Tool Kit Click here and download it now
July 27th, 2015 12:59am

function GetCurrentUsername() {
        var ctxt = new SP.ClientContext.get_current();
        this.website = ctxt.get_web();
        this.currentUser = website.get_currentUser();
        ctxt.load(currentUser);
        ctxt.executeQueryAsync(Function.createDelegate(this, this.onSucceessUser), Function.createDelegate(this, this.onFailUser));
    }

    function onSucceessUser(sender, args) {
        userID = currentUser.get_id();
        displayName = currentUser.get_title();

		FilterByCurrentUser();
    }

    function onFailUser(sender, args) {
        alert('request failed from user info :' + args.get_message() + '\n' + args.get_stackTrace());
    }

function FilterByCurrentUser() {
	
        var clientContext = new SP.ClientContext.get_current();		
		var oList = clientContext.get_web().get_lists().getByTitle('ListName');		
		var camlQuery = new SP.CamlQuery();
		camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'UserFieldName\' LookupId=\'TRUE\' /><Value Type=\'Int\'>' + userID + '</Value></Eq></Where></Query></View>');
		collListItem1 = oList.getItems(camlQuery);				
		clientContext.load(collListItem1, 'Include(ColumnName)');       		
		clientContext.executeQueryAsync(Function.createDelegate(this, this.onSucceess1), Function.createDelegate(this, this.onFail1));
    }

    function onSucceess1(sender, args) {
		var cnt = 0;
        var ListEnumerator = collListItem1.getEnumerator();
		while (ListEnumerator.moveNext()) {
		var oItem = ListEnumerator.get_current();	
			TargetedCampaigns.push(oItem.get_item('ColumnName'));
        }
		//Bind your data to html controls here
    }

    function onFail1(sender, args) {
        alert('request failed from user info :' + args.get_message() + '\n' + args.get_stackTrace());
    }
As per my understanding, above is the code example.
July 27th, 2015 2:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics