Setting Workflow Status to Custom Values

0 nhận xét
Setting Workflow Status to Custom Values
Workflow has few inbuilt status values such as "In Progress", "Completed", "Error Occurred", "Stopped" and "Failed on start". But what if we want to set a custom value for the workflow? A value, which we want the workflow to show whenever it is in progress or completed.

We can set a custom value for the workflow but this can only be done when we are designing our workflows in visual studio. Unfortunately, we cannot do this OOTB or using SharePoint Designer.
This can be done in both, Visual Studio Sequential workflows as well as Visual studio State Machine Workflows. To do this, open your workflow.xml and search for "" tag. Place the cursor just above it and write the below code :

"<"ExtendedStatusColumnValues">"
"<"StatusColumnValue">"Approved"<"/StatusColumnValue">"
"<"StatusColumnValue">"Rejected"<"/StatusColumnValue">"
"<"/ExtendedStatusColumnValues">"

(Please remove "" while writing this in workflow.xml as here it was not accepting the tags)
Now open the designer page and drag a "SetState" activity from your left hand side toolbox. Always Remember, there are two "SetState" activites, one is for setting the state in State Machine workflows and other is for setting the Workflow status to a custom value. The activity with a blue mark in it is used for setting the workflow status. Once you drag the "SetState" activity on the Designer page, right click on it and open its properties. Bind its "State" properties to a variable and select "field" while binding it. Select the correlation token as "WorkflowToken" as this activity does not belong to any task. Now double click the activity and you will come to the page where you need to write some code.

Let us assume that your "SetState" activity name is "PendingState". When you double click on the "SetState" activity, write the below line on the code window :

PendingState.State = (Int32)SPWorkflowStatus.MAX;

The integer value of the MAX is 15. From 0 to 14, the numbers are reserved for internal and builtin values such as InProgress, completed, error occurred etc. In workflow.xml, the value of the first custom value will be 15 (See above as we specified the first custom value as Approved). And then it will keep on increasing by 1. Like if we want to assign the "Rejected" value to the workflow then we will write the below line of code :

PendingState.State = (Int32)SPWorkflowStatus.MAX + 1;

The above line will assign the "Rejected" custom value to the State variable and whenever workflow reaches this state then it will show the status "Rejected". Like this we can write any number of custom values to the workflow. We have used only two custom values in the above Workflow.xml. If we want to use a third one then we will right it just below the "Rejected" custom value like :

"<"ExtendedStatusColumnValues">"
"<"StatusColumnValue">"Approved"<"/StatusColumnValue">"
"<"StatusColumnValue">"Rejected"<"/StatusColumnValue">"
"<"StatusColumnValue">"Pending"<"/StatusColumnValue">"
"<"/ExtendedStatusColumnValues">"

The value of "Pending" status will be assigned as follows :

PendingState.State = (Int32)SPWorkflowStatus.MAX + 2;

If you change your workflow.xml file by changing the workflow custom values then deploy it again and run iisreset to see the changes in SharePoint List when the workflow will run.

Like this we can set custom values to our Visual studio workflows.

Source:http://sharepointissues.blogspot.com

get SPUser from Login Name string

0 nhận xét
1. Issue:Can't get object SPUser with code behind people picker inInFopath anyway check .
currentWeb.EnsureUser(userName);
currentWeb.AllUsers[userName];
Whole 2 method are Exception .


3. Solution:
1. Add reference to dll microsoft.office.workflow.tasks (search ở C )
2. using function under to getobject SPUser from data input is login name (ex: fsdn\vinhtv; vinhtv-g5\admin..)

///
/// Gets the user.
///

/// The web.
/// Name of the user.
///
public SPUser GetUser(SPWeb web, string userName)
{
SPUser newUser = null;

try
{
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(web.Site.ID, web.Site.SystemAccount.UserToken))
{
using (SPWeb currentWeb = site.OpenWeb())
{
Contact contact = Contact.FromName(userName, currentWeb);

// if wthe user has already accessed teh site then id will be >=0
if (contact.PrincipalID < 0)
{
currentWeb.AllowUnsafeUpdates = true;

SPPrincipal p = contact.GetPrincipal(currentWeb);
}

newUser = currentWeb.SiteUsers[contact.LoginName];
currentWeb.AllowUnsafeUpdates = false;
}
}
});
}
catch (Exception ex)
{
throw ex;
}

return newUser;
}


Rource:VinhTv

Tisp share point

0 nhận xét

Sharepoint 2010 Error "You do not have permissions to access a database

1 nhận xét
First make sure the user has sufficient permission to access the database/web service.

Next, in infopath ->Tools ->Form Options ->Security and trust ->Uncheck “Automatically determine security level” (If database/webservice is on same domain then select domain else select proper option)

Now Convert your data connection in udcx file:

* For this, create a data connection library in MOSS
* Now open infopath form -> tools->Data connections
* Select data connection and click on “Convert… “ button
* Give the data connection library url with file name.
* Open Data Connection Library and Right click on udcx file -> "Approve/Reject" -> Select Approve and click OK.

Goto Central Administration ->Application Management->configure infopath form services-> and ensure the “Allow user form templates to use authentication information contained in data connection files” is checked.

If your database/web service is placed on another domain then you need to check next option “Allow cross-domain data access for user form templates that use connection settings in a data connection file”.

Source:social.msdn.microsoft.com

How to disable "Task has been changed" email alert?

0 nhận xét
e biggest disadvantage of SharePoint Task Lists is that they send "Task has been changed" mail whenever a task list item is changed. Even if you don't change the item, then also on the creation of the task the user get two mails. One is "Task is assigned" and the other is "Task has been changed".

I wanted that the user should get only one mail and that is for task assigned but i was not getting the way to solve this problem. My users were continuously complaining about this as they were really getting confused by getting two mails for the same task.

One day i read somewhere that whenever a task list is created, all the alerts are automatically created with it, like "Task has been assigned", "Task has been changed" and "Task has been deleted" mail alerts. Now i wanted to remove these mail alerts so that user should get only Task Assigned mail. I was also sure of one thing that there is no direct way of doing this thing and have to dig deeper in order to solve this.

I made use of SharePoint Manager. you can download this tool at the below link :
http://spm.codeplex.com/

This is a wonderful tool and is must for every SharePoint Developer. This tool is a SharePoint Object Model explorer. It gives you complete direct access to the properties and Object model of the SharePoint. With the help of this tool, I removed "Task has been changed" mail alerts. Let us see how.

Click on the SharePoint Manager exe and you will see your entire farm in an object oriented Model. All the Web Applications will be visible and then look for the Web Application, to which your site collection belongs. Expand that Web Application and then you will be able to see "Site Collection" term in the tree view. Expand it and you will see all the site collections in that web application. Select your site collection and expand it. Your site title will be mentioned and just next to it, a Team Site sign will be there. Expand that link and you will be able to see the term "Alert Collection". Once you expand it, all the task lists will be visible. Click on the task list (Where you want to disable change alerts) and look the properties on the right hand side. In that, look for "Event Type" property. Click the drop down and instead of "All" (which would be selected by default), select "Add". Once you select "Add" in the "Event Type" property, save your changes and the person to whom the task is assigned will get only "Task has been assigned mail.

In this way, i solve this problem and now users get only one mail and that is "Task has been assigned".

I would really appreciate if you can spend little time to poll or comment that whether this post was helpful for you or not. Your feedback matter a lot as that will enable me to improve the posts for my readers.

Source:sharepointissues.blogspot.com

Mails not going through SendEmail Activity

0 nhận xét
Finally i got the time to write after such a long time. Many times i have seen people writing on several forums that mails are not going through SendEmail activity albeit all the email settings are perfect. You will find this activity in SharePoint Designer as well as Visual Studio. I faced this problem in Visual Studio and the strangest thing was that the workflow was fine in the beginning and after 1 month, the mails just stopped going. Lets see how i made this work.

One day, in office, lot of people came to me complaining that their documents got approved but they did not get any mail. I asked everyone and not even a single person got the approval mail. Whenever this happens, the first thing is to check the workflow history. To check the workflow history, just click the workflow column (which show the status of the item) and you will see the workflow history just below. When i saw it then there was one error line saying "The email message cannot be sent. Please check your outgoing mail server settings".

I was sure that my outgoing mail settings were perfect as all the mails in other workflows were going. I designed a State Machine workflow in which i used "SendEmail" activity. I understood that the problem is in this activity only. There are two ways to configure the properties of a SendEmail activity :

1) By creating separate variables for "To", "From", "Subject" and "Body" tags in the properties window of the Designer page. That is, you define the variables by clicking that ellipse on the right hand side. And then use that variable in the code editor. For eg : If you defined variable of "To" in the Properties window as "SendEmail_To" then write the code : SendEmail_To = @"myemail@domain.com".

2) The second option is to use the properties of the SendEmail activity directly in the code editor. For eg : SendEmail.To = @"myemail@domain.com". In this case, we do not bind the variables in the properties window as we do in the first case.

Now i was following the second method and my mails just stopped going after one month as mentioned before. The only solution to this problem was to switch to first method. I tried it just like that, without any reason and damn........... it worked. Yes, after that my mails started going and its been a year now, i did not face any problem.

I still do not have the explanation for why the second method did not work. Really strange. Later on, many people wrote this issue on the MSDN Forums and i suggested them this solution and it helped them a lot. So i thought of writing this so that more people will be free from this hair pulling issue.
Hope you liked reading it.

Source:sharepointissues.blogspot.com

Auto Generating ID in Infopath (Without Code)

0 nhận xét
I have already discussed about how to generate an automatic ID in Infopath with the help of Programming. Well, many people are not very much familiar from writing code and they prefer a no code solution. So, I thought of explaining the same concept without code.

There are certain inbuilt functions in Infopath which many times save your hell lot of effort and also provides good flexibility to manage your applications. One of them is the "Count" function which, as the name suggests, count the number of items in the node. We will make use of this function to generate an ID.

Let us take the same example which I took in the last post to explain the same concept but with code. We have an Infopath form which we use to file the review meetings of the project every week. The submitted Infopath form is named in such a way that the name is the concatenation of the name of the Project and the next count. Like, If the Project name is "A" and already 5 items for this project are there in the list then the name of the next infopath form will be : A_6. Project name is entered by the user while filling the form. The number "6" is calculated with the help of the "Count" function in the Infopath form and let us see how.

Design the Infopath form by creating all the fields like Project Name, Today's Date etc. as per your requirements. Publish this Infopath form and make it as a content type in the form library. Then we need to make a receive data connection referring this Library and click the field "Project_Name" while making this connection as it will ask you to select the fields whose values you want to enter in the form. Now create a field in the Infopath form and name it "ItemsCount". Open the properties of this field and click the button just next to the place where you enter the default value. Select the "Count()" function and you will see that it will be asking you to enter a field from the form as a parameter. Click on that parameter and select the receive data connection you just created. It will show you the field "Project_Name" as while creating this connection, you clicked it. Select this field and instead of clicking the "Ok" button after that, just click the "Filter" button. Click on "Add" button and you will see three drop down boxes. Now select the "ProjectName" field of the Infopath form in the first drop down box. In the second drop down box, select "is equal to" and in the third drop down, select the receive data connection and in that select "Project_Name"(This is the field in the Form Library) . In short, we have written a query that will give us the count of the items in the form library where the project name is the one which is entered by the user. So if the user selected Project "A" in the Project Name field in Infopath then this will give us the count of the number of items where the Project name is "A" in the list.

Now create a new field and name it "ID". Open its properties and from the list of inbuilt functions, select "Concat()". This function is used for concatenation and by using this we will concatenate two fields. The default value of the ID field will be :
concat(ProjectName, "_", (ItemsCount + 1))

Here, ProjectName and ItemsCount are the field from the Infopath form. As you can see that we have added 1 to the ItemsCount function, so we will always get the next ID while submitting this form. Make the "ID" field as name of the submitted form and it will always give you the next number.
(I am so sorry for not giving the screenshots)..........

In my last post, I explained this same concept with a CODE solution. Well, the choice completely depends upon the application's requirements, its complexity and your ease. I use both the solutions depending on several factors. I prefer a no code solution when my application is simple and I just need to generate an ID. But if my application is complex and I am aware that further more requirements will be introduced then I go for a Code solution as it provides great flexibility to change your application. That is why I wrote two different posts to explain the same concept so that users can decide their option depending upon several factors.

If possible, please spend little time to poll or comment that whether this post was helpful to you or not. Your feedback matter a lot as that will enable me to improve the posts for my readers.

Posted by Ginni Atul Sharma at 9:38 PM 1 comments
Labels: Infopath
Reactions:
Friday, November 26, 2010
Auto Generating ID in Infopath (With Code)
Things would have been so easy if there would have been an autogenating ID feature in Infopath form library. To track the number of items, a column naming "ID" is there in every list but it does not serve any useful purpose when an item is deleted. This is because, it is not effected by the deletion of the items and keep counting them as and when the items are added. So if 5 items are added and you delete one of them, then the next count will be 6 only and not 5.
Well, things are not that much difficult and I figured out an easy solution to achieve this task. But with one condition and that is to use SharePoint Object Model. We will start this with an example as that will make things very clear.

Let us suppose that we are designing an Infopath form with programming and I am writing this code in the submit event handler. We have a scenario of calling meetings of a particular project by filling the Infopath form. Once the form is submitted, a mail goes to all the team members about the details of the meeting and the submit title of the form is "Project Name_Meetings Count". This means that if Project A is there and if I am filling its 5th meeting then the title will be "Project A_5". This value is generated automatically through code in the submit event handler and is then assigned to a field in the Infopath form. The most important thing over here is the count and lets see that how is this calculated.

We have a field in the Infopath form naming "Project Name" which the user enters while filling the form. When he submits the form, I run a CAML Query to calculate the count of the items, having the name of the Project specified by the person in the form. Then this count is added by one to calculate the next ID and this ID is then assigned to the Infopath field "SubmitName" which is the name of the submitted form.

//First Retrieving the value entered by the User
XPathNavigator MyNavigator = MainDataSource.CreateNavigator();
string ProjName = MyNavigator.SelectSingleNode("//my:ProjectName", NameSpaceManager).Value;

SPWeb MyWeb = null;
using SPSecurity.RunwithElevatedPrivilidges(delegate ()
{
using(SPSite MySite = new MySite("Your site URL"))
{
MyWeb = MySite.OpenWeb();
}
});

//Retrieving the List
SPList MyList = MyWeb.GetList("Your List URL");
string FieldIntName = MyList.Fields["Project Name"].InternalName.ToString();

//Running CAML Query to get the count of the Project Name entered by the User.
SPQuery MyQuery = new SPQuery();
MyQuery.Query = (See this Link to write a CAML query) http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

In the Field Ref, you need to write "FieldIntName", which is the Internal Name of the Project name and this is a column in the list.
In the Value, you need to write "ProjName", which is the name of the Project entered by the user while filling the form.

//Fetching all the items satisfying the above query.
SPListItemCollection AllItems = MyList.GetItems(MyQuery);
int Count = AllItems.Count; //This gives us the count of the items having the project name entered by the user.

In order to create a new ID, we will add one to the total count and will concatenate this ID with the Project Name. So like this, our ID will automatically be generated every time a new item is added. And, it will not be affected with the deletion of items as the count is calculated on the basis of items added in the list.

//Final ID will be :
string SubmitID = ProjName + "_" + (Count + 1);

//Assign this to the field in the infopath form which will be the name of the submitted form
XPathNavigator formNav = MainDataSource.CreateNavigator;
formNav.SelectSingleNode("//my:SubmitName", NameSpaceManager).SetValue(SubmitID);

Now when the form is submitted, a CAML query is run to calculate the count. And then, one is added to the total count to generate the next ID.

The same thing can be done without programming also which I will be explaining in my next post. I know that you all must be wondering that if this is possible without programming then why to go for a programming option. Well, the answer is that the programming option gives you great flexibility and you can further customize your application depending upon the requirements. I use both the options depending upon the complexity of my task. If i just need to generate an ID then I go with no code solution. But if I have to do several other complex tasks then I go with programming option. Always, the choice is your.

Source:sharepointissues.blogspot.com