0

Ok, this is the issue: I have a Data View web part which I would like to filter depending the "office" the user logged in belongs. I can get this using SPServices (GetUserProfileByName):

JS

$().SPServices({
operation: "GetUserProfileByName",
completefunc: function (data, status) {

    $(data.responseText).find("PropertyData").each(function (idx, val) {
        var $val = $(val);
        var name = $val.find("Name").text();
        var value = $val.find("Value").text();
        profile[name] = value;
    });
    // profile.PreferredName //it gets name
    //profile.WorkEmail //it gets email
    // profile.Office; // it gets office
}
});

Is it possible to change SPDataSource in XSLT using this "profile.Office" value? It looks like I have to somehow dynamically change this CAML query in the SharePoint:SPDataSource tag:

XSLT

SelectCommand="<View><Query><Where><And><Eq><FieldRef Name="Regional_x0020_Office"/><Value Type="Text">Billings, MT</Value></Eq><Eq><FieldRef Name="Fiscal_x0020_Year"/><Value Type="Text">2014</Value></Eq></And></Where></Query></View>" 

But I can't figure out how to change Fiscal_x0020_Year and Regional_x0020_Office using SPServices. Just to let you know, I cannot use anything server side code, or C#, etc. I'm limited to javascript (jQuery, etc). Thanks in advance!

2

The dataview web part is executed server side, so you can't use jQuery to manipulate the SelectCommand.

You would need to remove rows from the DOM with jQuery after the web part has loaded.

I would use jQuery to hide the web part initially. Then, make your SPServices call to get the user's Office. Then iterate over each row of the table and if the Office field does not equal the user's office, remove the row from the DOM. Then after it iterates over each row, show the web part.

  • Is there a way of doing this using parameters or something else? The thing is that we have 10 offices and I would like to create only one web part that would be used by all users. Depending what office the user belongs to it will filter the data view to only show his office data. I've been looking into CAML <Membership> (Each office has its own Group), but I can't figure it out. thanks! – cubanGuy Jul 16 '14 at 17:20
  • How many items are in the list? Filtering it with jQuery after it is loaded based on the current user would still be one web part. – Eric Alexander Jul 16 '14 at 17:22
  • Well, I thought about it too, but the issue is that there 10 offices, and each one will have a row per Fiscal Year. The data started being collected last year, so at this moment would be 10 (offices) x 12 (months) x 2 (years), but as time passes it will get a lot bigger.The other issue is that I also would like to use the same Filter (or similar) if possible in the Edit or Add Forms. Display should not be an issue just using SPServices GetListItems, but editing is the one that kills me. Thanks again! – cubanGuy Jul 16 '14 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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