Monthly Archives: November 2012

Get Current User in SharePoint List

Make a new person/group column and use this code in web part to assign any desired person/group column to get the value of current user. In this code ‘Test’ is a list name and ‘Originator’ is the person/group column to get the value of current user once the web part initiated.

Error Opening/Editing Word from SharePoint

Somehow when i’m trying to open word in SharePoint i got an error that says something like this

Enough to say that it annoys me. It has something to do with Microsoft Office 2010 security. You have to disable protected view from security setting. Just go to ‘File’, ‘Options’ and it will bring you to ‘Word Option’. Click ‘Trust Center’, and ‘Trust Center Settings…’

Click ‘Protected View’ and untick all the options. Click ok and you’re done! Thanks to Nikspatel. View his blog to read more.

To Check If Column Is Null

Recently im having an issue regarding checking value of column list in workflow. What im planning to do is to check if a certain column has value or null. Certain state will be assigned depending on the value (null or not null). This is the thread that i’ve created to seek for help from professional

Luckily 2 kind gentlemen came to the rescue. Suggesting solution for this issue. At first i don’t see much difference their solutions with mine but after detail explanation and experiment this is what i came up with. This is the original code.

but when i debug, it says ‘object reference not set to an instance of an object’ although the value is null. After playing for a while that’s when i decided i need to seek for professionals help. Hemendra suggested that i should be using string checker2 = Convert.ToString(workflowProperties.Item[“Checker 2”]) to check if the column value is null or otherwise. When i debug there’s no more error stating that ‘object reference not set to an instance of an object’ but the program still didn’t go as i planned it although the value is null. Then ParthaStarSp suggested me should be using If (workflowProperties.Item[“Checker 2”] == Null). Just remove the string and it does the job. It really bugs me at first. I will quote their comments “There is a difference. When you get string data using ToString() and value is null then you will get the casting error but when you use my code then it will cast the string and avoid the error. If you have any doubt then check and see the result.”-Hemendra, “My suggestion is always to check the object whether its NULL and if it is not NULL then use the object’s value. I recommend this as the best practice… this is what we have been doing for several years...”-PrathaStarSp

I make an initiative to do some research to know the difference between .ToString() and Conver.ToString(). I’ll just copy from this forum.

Lets understand the difference via this example:

We can convert the integer i using i.ToString () or Convert.ToString. So what’s the difference?

The basic difference between them is the Convert function handles NULLS while i.ToString ()does not; it will throw a NULL reference exception error. So as good coding practice using convert is always safe.

This is just like what Hemendra said about casting error when i use .ToString() and not Convert.ToString(). But why i cannot get the value null and use it as comparison when i’m using Convert.ToString()? This is the answer.

Calling ToString() on an object presumes that the object is not null (since an object needs to exist to call an instance method on it). Convert.ToString(obj) doesn’t need to presume the object is not null (as it is a static method on the Convert class), but instead will return String.Empty if it is null.

There you have it. Convert.ToString() does not return null when it’s empty but instead will return String.Empty if it is null.

Getting Value From List in Workflow

There is a time when you need to check if the value in the list is empty or otherwise via workflow. Using this code you can get value of list column and you can check it in workflow.

Let’s say you want to check ‘checker 1’ column in task list. Then you want to assign state according to the value in ‘checker 1’, you can use workflowProperties. WorkflowProperties is an object created from the class SPWorkflowActivationProperties, which make the link between the workflow and the SharePoint context.

 

Other than that you can use onTaskChanged. Here is an example

[sour

This code will check the value of ‘status’ column after any changes occur in ‘ontaskchanged1’ event driven.

Visual Studio: Creating Sequential Workflow for SharePoint

This is another option for creating workflow in visual studio. In my opinion sequential is more suitable for simple and non-complex workflow. Although it is not as dynamic as state machine workflow i think it is best for you to experience both to compare it yourself.

[youtube=http://www.youtube.com/watch?v=reewETLjde8]