Creating New Multi-Lookup Values from Custom Forms


I was working with a client where they wanted to add a new Multi-Lookup value on the New Item form. This will be a customized new item form that will add a link to popup a new item of that multi-lookup value. SPServices has something that will add the SPLookup (http://spservices.codeplex.com/wikipage?title=$().SPServices.SPLookupAddNew&referringTitle=Documentation), but wasn’t verified for SharePoint 2013 and had caveats for 2010, so I was unsure about the solution. I read some blogs that show you how to explicitly add a new lookup value, using the following format:

|t<ID>|t<LOOKUPVALUE>|t

where <ID> = the ID of the lookup item and <LOOKUPVALUE> = the lookup value/text of the item

The tricky part to this is that there are <select> tags and <input> tags that are hidden that you need to add and remove, this will force you to reinvent the wheel of adding and removing the option from the two panel display:

 

I think I was tackling it from a different angle, so I just used the refresh and with HTML5, you have the ability to use localStorage. localStorage is used for what cookies previously was used for in the prior versions. You can write and store key/value pairs that will stay with the browser even after you close the browser out (much like a cookie). So I think it may be easier to capture the values of the form, and reinsert the values whenever the new item is added and the form is refreshed.

<script type=”text/javascript” src=”../../Style Library/js/jquery-1.11.1.min.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){

$(“input[id$='TextField']“).filter(“input[title='Name']“).val(localStorage.getItem(‘name’));
$(“input[id$='TextField']“).filter(“input[title='Address']“).val(localStorage.getItem(‘address’));
$(“input[id$='TextField']“).filter(“input[title='Address 2']“).val(localStorage.getItem(‘address2′));
$(“input[id$='TextField']“).filter(“input[title='City']“).val(localStorage.getItem(‘city’));

localStorage.removeItem(‘name’);
localStorage.removeItem(‘address’);
localStorage.removeItem(‘address2′);
localStorage.removeItem(‘city’);

});

function AddNewRig()
{

OpenPopUpPage(‘/../../Lists/<List>/NewForm.aspx?IsDlg=1′,  AddItemRefresh);
}

function AddItemRefresh()

{

var name = $(“input[id$='TextField']“).filter(“input[title='Name']“).val();
var address = $(“input[id$='TextField']“).filter(“input[title='Address']“).val();
var address2 = $(“input[id$='TextField']“).filter(“input[title='Address 2']“).val();
var city = $(“input[id$='TextField']“).filter(“input[title='City']“).val();
localStorage.setItem(“name”, name );
localStorage.setItem(“address”, address);
localStorage.setItem(“address2″, address2 );
localStorage.setItem(“city”, city);
location.reload();

}

</script>

 

Basically, upon loading the form, it will look for the localstorage keys, then set the form values for each textbox/control. You then delete the keys so that it doesn’t conflict with any other applications that use it. SharePoint will handle the loading of the Multi-lookup control with the new item that the user just created, so whenever you refresh the page, the form will load the Item you just added while retaining any information that the user previously put inside the form. A new key/value pair will have to be set/get/deleted for each column or field in the form.

 

Workflows running twice


I’ve found that in some cases during a migration, workflows may have the ability to run twice. You can even start a brand new workflow for a list, and even that will run twice. I looked more into it, and it appears that upon migration, both the 14 and 15 version event receivers were present. I did some powershell to find and remove the 14 (I’m on SP2013) event receivers.

$spWeb = Get-SPWeb -Identity http://sitewebappURL

$spList = $spWeb.Lists["List Name Here"]

$spList.EventReceivers | Format-List Id, Assembly, Type, Class

#Find the event receivers of ItemAdded and ItemUpdated for the old version (14 if you are on sp2013, 12 if you are on sp2010, so on). Make sure this output spits out the correct receiver you are trying to delete!

$spList.EventReceivers[#]

#Use the following command to delete the old version of the event receiver. Be careful not to delete the wrong one!

$spList.EventReceivers[#].Delete()

$spList.Update()

Then, try the workflow out again, and it should only run once.

Passing Current User to another web application (ASPX)


Man, it’s been awhile since I lasted did a post. There have been a lot of changes. I have a new job and am doing consultant work now. I’m diving much more into SharePoint 2013. In fact, I am taking the 70-331 exam this month, so that should be a good step up for my bag of certifications. Anywho..

I had a requirement where I needed to grab the current user and pass the username off to another web application. How I got it to work was to embed the web application in a SharePoint app which just consisted of a web application page. All you need to do is:

1. Start up Visual Studios -> New -> Project -> SharePoint Empty Project (2013)
2. Then right click the Project -> Add -> New Item -> Application Page.
3. From here, make your application page the same page that you want to embed, carrying over any supporting files.
4. Make sure from here the application page runs correctly (taking note that there is no credential passing yet)
5. Add a reference to Microsoft.SharePoint to your project.
6. Then, let’s assume your app page is called Default. You want to edit your .aspx.cs file

Add:

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

Also add on Default.aspx.cs:

SPWeb theSite = SPControl.GetContextWeb(Context);
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;

Now you have control over the SPContext, so you can use that to pass objects off to the web application you need it to be.

SharePoint Designer Workflow – E-mail Body String


So I was working on a SharePoint Designer workflow and it seems as though the e-mail body was not rendering or reading the text that was in the body, it was including all of the markup with it. I was trying to include the body of an email to log to the history list.

lookupbodyworkflow

When the workflow ran, the email body output looked like this:

Image

The problem here is that the Body column is allowing Rich Format. All you have to do is change the Body format back to Plain Text.
Image

Then try to use your workflow again using E-mail Body (as string). It should show up correctly now.

Moving SharePoint Designer Workflows


So I decided to make the move and promote my site to a site collection because they were getting a little big and put that site collection on it’s own content database. I used purchased 3rd party tools, so don’t ask me how I did that. ;) Anyway, I had these nicely developed Sharepoint Designer workflows that I have in the mix and I definitely don’t want to recreate them and I don’t want to lose them. How about moving them? Can I do that? I did some research and I’ll post how I did that successfully here.

(It’s been awhile huh?)

First, go to the site you have the workflows on. The source site if you will. From here, Click Site Actions -> Edit in SharePoint Designer.

From there Click the “All Files” in the Navigation, then click “Workflows”
allfiles

workflows

Right-Click the workflow you would like to copy. And go to “Copy”

copyworkflow

Don’t close SharePoint Designer. Go to your destination site (wherever you want to move these puppies to). Go to Site Actions -> Edit in SharePoint Designer.

Go to All Files -> Workflows (**If you don’t have “Workflows” available to you, you can make a quick SharePoint Designer workflow on a random list and publish it, then restart SharePoint Designer.)

Right Click and choose “Paste”. The workflows should be there, but they are not associated with the list that you want since SharePoint recognizes and attaches workflows to Lists and Libraries using their ListID. We can change that through the .xoml.wfconfig.xml

In SharePoint Designer, go to “Lists and Libraries” in the navigation, then select the list or library you want to associate the workflow with. This should bring up the List/Library settings.

listview

The ListID is what you are looking for. Copy this. Ignore the brackets, Mine will be:

35DAE9D1-85F7-4C95-A155-09072263F146

Now let’s go back to the workflow you copied over earlier. Click the “All Files” again in the navigation, then click “Workflows”, then click the workflow name. This should bring you to the files associated to that workflow.
Right-Click the .xoml.wfconfig.xml and select Open With -> SharePoint Designer (Open as XML). This is what you get.

wfconfig

The highlighted part is what you are pasting that ListID to. Delete the ListID, and paste the ListID you copied earlier here. Save the file and close down out of SharePoint Designer completely. Then start SharePoint Designer back up and you should see the Workflow available in the “Workflows” section in the navigation. Open the workflow up and hit Publish to publish it to the destination site. You should be good to go from there! Enjoy!

Hidden folders in Explorer View


I noticed this morning that one of my users (actually would be several, but this is the first user I troubleshooted) had 3 folders missing from the explorer view of a document library. They were oddly named with the first character being an underscore(_).

So digging a little deeper, I smacked my forehead and remembered that underscore is Windows’ way of determining whether or not a folder should be hidden. So I copied the folders to my desktop, deleted the folders on SharePoint, renamed them without the (_)underscore, and put the files back.

The user can now see the folders.

 

 

Discussion board threading in reverse chronological order


Your threading view should be set up as the following:

Columns:

  • Threaded(threading)

Sort:

  • First sort by: Threading -> Show items in descending order
  • Then sort by: Created -> Show items in descending order
  • Uncheck “Sort only by specified criteria”

Folders:

  • Show all items without folders
  • Show this view: In folders of content type “Discussion”

This setup worked for me.

 

Note: Do NOT change the Folder Option: Show in this view to “In all folders” or “In the top-folder level” because it will throw an error when using discussion boards of type: 

Attempted to use an object that has ceased to exist. (Exception from HRESULT:
0x80030102 (STG_E_REVERTED))

 

Follow

Get every new post delivered to your Inbox.