Thursday, November 19, 2009

Running Sharepoint workflow in a loop

After installing MOSS service pack 2 some of the SPD workflows are not invoked when it calls itself. To solve this problem following method can be used.

In this solution , one workflow invoke the other one and continue in a loop. Loop is broken by using some conditions.

Workflow 1 (Test) - :
This is the main workflow which contains the business logic. For my example I use this workflow to create a task for the “Test List” entry.

Workflow 2 (Test 1) -:
This is a used for run the workflow 1 (Test) in a loop.

In the “Test List” three fields has been created as follows.



A new Item is added to the “Test List” as follows.



Here this should create 3 tasks in the task list and the workflow 1(Test) is given below



Here a new task is created (Task name = Title of the entry + Current number) and “Current number” is increased by 1. Then the workflow is paused for 1 minute. After completing the pausing “Task Created” set as “Yes” and stop (since now workflows are not run in a loop). Now workflow 2 (Test 1) starts to run. See the workflow 2 (Test 1) below.



Now workflow 2 check whether the value of current number is less than the value of maximum number. If it’s true that set the value of “Task Created” to “No”. Since this is an update, workflow 1 (Test) is invoked and it runs second cycle. If the value of current number is greater than the value of maximum number then the workflow 2 (Test 2) is stopped and that breaks the loop. Workflow 1 (Test) won’t be invoked again.

Please see the following steps to check the flow.



Three tasks has been created in the task list.

Thursday, October 8, 2009

Quering Calendar Recurrence Events

Recurrence Events in sharepoint calenders is another web part that creats calendar events for given time, daily, weekly or monthly. So how you can read this event back and get the set of recurrences behind the event? Its quite simple with CAML.But its important to understande the logic.

Check the following query



Here we retrieve all the recurences for current day.




This part will filter this data set for recurrences.

If you need to collect recurences for given day, set the calendar date of the query as follows and run the above CAML query.

Query.ExpandRecurrence = true;
Query.CalendarDate = new DateTime(2009,10,15);

You can add some more condions to this query and filter the data set. As an example folowing query will retrieve one recurrence of perticular event.

Thursday, July 16, 2009

Hide A Column In A Sharepoint List

Hiding a column in a share point list is quite simple. Follow steps as below.

I have a sample share point list called “Testing ” and lets start.



Step 1:-
Open the list and go to settings. Then you can see the all columns in the list.




Step 2:-
Create the new columns. I’m going to create a column called “My Hidden Column”.



Step 3:-
We can hide our columns through the content type. To do that content type management should be enabled. Go to advanced settings as follows.



Now select “Yes” in “Allow management of content types” option and press OK



Step 4:-
Now you can see the content type management in list settings as follows.



Click on the content type and following screen will be displayed.



Step 5:-
Now select “Hidden” option and press OK.



That’s all.

Tuesday, June 16, 2009

New SharePoint Tools in VS2010

The next version of SharePoint will be built on the .NET 4.0 framework. Chitsaz indicates the new Visual Studio tools will be Version 1. The tools are a mix of Designers and RAD tooling for the core scenarios but also some things that cover the breadth of SharePoint development.

New Templates
The new version of Visual Studio brings us a number of new templates for SharePoint components. The screenshot below is just the start of what new templates we can look forward to.


Visual Studio 2010 - SharePoint templates


Server Explorer
The Server Explorer connects to a SharePoint implementation and shows you all the artifacts including sites, document libraries, lists. You can click on an item and view the properties of it in the Properties tab.


Visual Studio 2010 Server Explorer for SharePoint


Feature Designer
The Feature Designer provides a detailed look at all the components of a Feature.


Visual Studio 2010 - Feature Designer


Package Explorer
The Package Explorer shows you all the items inside the package in a WYSIWYG view. You are able to drag and drop items around to create your package differently.

You can also add your solution to source control.


Visual Studio 2010 - Package Explorer


Building and Deploying Solutions
Currently, you have to package up your solution and deploy it manually to SharePoint. Debugging is also not something you can easily do. This will change with VS2010 — F5 will now allow you to compile, build, debug and deploy SharePoint solutions.

Integration with Team System
Not only can you now easily add your SharePoint solutions to Source Control, you can also integrate with Team System giving you MS Build Support and nightly build functionality. This will go a long way to helping teams of developers collaborate on SharePoint features.

Tuesday, April 21, 2009

How to Update Multi Valued Lookup Filed in MOSS 2007.

Hi...

Updating multiple values in a lookup column in MOSS is bit hard due to some limitations in MOSS 2007.
Here is a simple method to update multi valued lookup column in MOSS 2007. So what should be appropriate technology?

All the MOSS (Microsoft Office Share Point) developers tend to use Microsoft Office Share Point Designer 2007 as simple development tool for workflow development, Web Parts etc… I’m going to integrate this tool with Visual Studio .NET 2008 and then update our multi valued lookup column using workflow.

First we create a workflow action and then the action is attached to our workflow through Microsoft Office Share Point Designer 2007.

Let’s create the workflow action

Lookup column is in Department List
Lookup column name = Members
Target List = Member List



sing System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;


namespace UpdateMultipleMembers
{
public partial class UpdateContacts: SequenceActivity
{
public UpdateMembers ()
{
InitializeComponent();
}

private EventLog _log;


We have to define three varables as follows. Code snippts in VS 2008 help us to create this varables.

public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(UpdateContacts));

[DescriptionAttribute("__Context")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public WorkflowContext __Context
{
get
{
return ((WorkflowContext)(base.GetValue(UpdateContacts.__ContextProperty)));
}
set
{
base.SetValue(UpdateContacts.__ContextProperty, value);
}
}

public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(UpdateContacts));

[DescriptionAttribute("ListId")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string ListId
{
get
{
return ((string)(base.GetValue(UpdateContacts.ListIdProperty)));
}
set
{
base.SetValue(UpdateContacts.ListIdProperty, value);
}
}

public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(UpdateContacts));

[DescriptionAttribute("ListItem")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int ListItem
{
get
{
return ((int)(base.GetValue(UpdateContacts.ListItemProperty)));
}
set
{
base.SetValue(UpdateContacts.ListItemProperty, value);
}
}


Now we define the action inside “Execute” method.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
_log = new EventLog("Multiple Members Workflow");
_log.Source = "Share Point Workflows";

try
{

SPSite _site = (SPSite)(__Context.Site);
SPWeb _web = (SPWeb)(__Context.Web);
SPList _list = _web.Lists[new Guid(this.ListId)];
SPListItem _listItem = _list.GetItemById(this.ListItem);

UpdateLastComdate(_web, _listItem);

}
catch (ExecutionEngineException ex)
{
_log.WriteEntry("Error" + ex.Message.ToString(), EventLogEntryType.Error);
}
return ActivityExecutionStatus.Closed;
}

Here we retrieve date values from Department list and update our lookup list (Members).

private void UpdateLastComdate(SPWeb _web, SPListItem _listItem)
{
string[] contacts = _listItem["Department"].ToString().Split('#', ';');
DateTime Date = Convert.ToDateTime(_listItem["Date"]);

int _length = contacts.Length;

string[] contactID = new string[_length / 2];
string[] contactName = new string[_length / 2];

int j = 0;
int k = 0;

for (int i = 0; i < mylist2 =" _web.Lists[" i =" 0;" id =" Convert.ToInt32(contactID[i]);" _listitem2 =" myList2.GetItemById(id);">”

Underneath this tag “authorizedtypes”

Add this tag

authorizedtype publickeytoken="public Key" culture="neutral," version="1.0.0.0," assembly="”UpdateMultipleMembers," namespace="”" typename="”*”" authorized="”True”"


3. Update .ACTION file

Open C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow folder

Open “WSS.ACTIONS” file in note pad

Append following code before /actions tag (Fill “<>” with the key in GAC)

Action Name=”Update Multiple Member Records”
ClassName=” UpdateMultipleMembers. UpdateMembers”
Assembly=” UpdateMultipleMembers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken= add the key here”
AppliesTo=”all”
Category=”Extras”

ruledesigner sentence="”"
fieldbind id="”1”" designertype="”ChooseListItem”" text="”this" field="”ListId,ListItem”"
/ruledesigner

parameters
parameter direction="”In”" type="”Microsoft.SharePoint.WorkflowActions.WorkflowContext”" name="”__Context”"
parameter direction="”In”" type="”System.String," name="”ListId”"
parameter direction="”In”" type="”System.Int32," name="”ListItem”"
/parameters
/action

Now you can see this action in share point designer as a custom action and then create the workflow using our custom action “Update Multiple Member Records”.

Enjoy...

Wednesday, January 21, 2009

Dynamic CRM 3.0 - Print Unsaved Data

Microsft Dynamic CRM 3.0 never alows you to print unsaved data. System check the availability of dirty data. Lets see how to stop this dirty check and print unsaved data.

first we have to find the print() function. open WWWROOT folder and go to INETPUB in your machine.

Then open this folder :\Inetpub\wwwroot\_forms\controls

Open form.crm.htc file

find the Print() function.

function Print()
{
if (isDirty())
{
alert(LOCID_FORM_PRINT_DIRTY_MESSAGE);
}
else
{
var sId = _oSubmitForm.crmFormSubmitId.value;
openStdWin("/_forms/print/print.aspx?objectType=" + _oSubmitForm.crmFormSubmitObjectType.value + "&id=" + sId + "&title=" + encodeURIComponent(parent.document.title), "print" + buildWinName(sId));
}
}

Here you can see that system check dirty values on the form. so edit the code according to your needs and skip validating dirty values. Then you can print your CRM form.

Following example shows how to skip this dirty check for a specific entity using the object type code.

function Print()
{
if(parentForm.ObjectTypeCode == 10034)
{
var sId = _oSubmitForm.crmFormSubmitId.value;
openStdWin("/_forms/print/print.aspx?objectType=" + _oSubmitForm.crmFormSubmitObjectType.value + "&id=" + sId + "&title=" + encodeURIComponent(parent.document.title), "print" + buildWinName(sId));
}
else
{
if (isDirty())
{
alert(LOCID_FORM_PRINT_DIRTY_MESSAGE);
}
else
{
var sId = _oSubmitForm.crmFormSubmitId.value;
openStdWin("/_forms/print/print.aspx?objectType=" + _oSubmitForm.crmFormSubmitObjectType.value + "&id=" + sId + "&title=" + encodeURIComponent(parent.document.title), "print" + buildWinName(sId));
}
}
}

Welcome 2009