Richie H’s Weblog

Sharepoint and Stuff

Posts Tagged ‘moss’

Sharepoint Designer Workflow

Posted by richieh77 on May 27, 2008

Having avoided workflow for many months, I finally had a project which required me to build a time sheet type application.
The idea was that the user would have a number of tick boxes and a time sheet record for each week.

I started off by creating the Time Sheet library with the appropriate columns, for each Yes/No column I created a mirror calculated column for storing a numerical value.  The calculation basically said if checked then 1 else 0(actual statement is =IF(myField=TRUE,1,0).

To create a weekly total I created a workflow in designer that was fired on the update event.
  image

This is where my major problems started, the first thing I noticed was that the work flow took ages to complete if it ever did, and when I clicked the item I either received a “Server Out of Memory” message or a “Some part of your SQL statement is nested too deeply” error message.

I traced all of my problems back to the Set Total to Variable:Total statement.  Apparently, if within your workflow you update a field on the current item and you have the run workflow when item is updated ticked, the code will disappear into a never ending loop.

The only way I have found to stop this is to use a semaphore type approach.  Basically I have a column on the form called update record.  By default the column is set to No.  If the user wishes to submit their record they have to tick the Submit Record box.  Within the workflow I have coded a condition which says if Submit Record equals Yes then do the calculation, within this branch I then set the Submit Record back to No and then update the Total. 

This does not stop the workflow from firing it will fire twice per update, but the 2nd time will do nothing as the condition will be false.

I will be looking at ways to do this via script on the edit form and will keep you posted.

Posted in Sharepoint | Tagged: , , , , , , , | 2 Comments »

Searching Woe’s

Posted by richieh77 on April 15, 2008

Having had a request to enable wildcard search we spent sometime looking for products that would help with it.

Anyone who’s done this will know there is a very good provider who are offering a free solution.
The issue we have had is that after implementing the solution we were no longer receiving search usage data.

Having spent several days looking for the cause I discovered that if you deploy the Out of the Box Sharepoint Search Text Box web part to the results page, you got the data, if you used the results one you didn’t.
The upshot of this was that, as the provider had used a custom Search box, the Sharepoint data in our instance never got recorded unless we deployed the standard search box  to the results page.

Having done some further research I discovered that all MOSS Search web parts utilise a Sealed object Microsoft.Office.Server.Search.WebControls.SearchResultHiddenObject

This object is  responsible for handling best bets, relevance, results and running the query itself.  It is within here I believe the usage data is updated.  Despite crawling through the API libraries I can find no methods to update the Search Usage.  It would also appear that the information isn’t picked up from the log files so again I assume the updating is all handled via this object.

 

If this is the case it will not be possible to run bespoke queries and get the usage data to report on the terms/results.

 

Anyone agree/disagree with this, I have posted all over the place but not received any response

Here are some links to other information round searching.

http://msdn2.microsoft.com/en-us/library/bb608304.aspx

http://www.sharepointforum.com/en-US/Wiki/The%20good%20news%20and%20the%20bad%20news%20on%20MOSS%202007%20search.aspx

Posted in Sharepoint | Tagged: , , , , | Leave a Comment »

Creating Site Collections and Groups

Posted by richieh77 on February 9, 2008

Ok, so one of the jobs I needed to do was automatically create a Site Collection and then create the members, owners and visitors groups.

The first job is to get hold of the web application

SPWebApplication spWA= SPWebApplication.Lookup(new Uri(http://mySite));

Next you can use the Sites collection to create the appropriate Site Collection
The new site collections URL can either be in the format mySiteCollection or managedpath/mySiteCollection

int32 lcid=1033;
string template="STS#2" //Get the one you want
here
SPSite spS=spWA.Sites.Add(url,"SiteName","SiteDescription",lcid,template,"\\domain\ownerloginname","Owner Name",
myemail@here.com)
There are a number of Add methods allowing you to configure owners, secondary owners, and config databases.  Full list here

Once you have done this you will need to add the groups.
This is quite straight forward using the new site collections rootweb property and inturn the SiteGrpups collection

SPWeb spW=spS.rootWeb;

The trick now is to add the group.  The issue here is that you will need an SPMember object which is either SPGroup or SPUser for the owner object.
The problem I encountered is that unless the user is part of the Root Web then they can’t be added as a Group owner.  The group will half create and the API will not throw an Exception.  What you will end up with is a Link in the Site Groups area of teh Site Collection, that errors when clicked. Also the SiteGroups count property will not reflect the new group, but you will not be able to add a group with the same name without receiving a name already exists exception

There are several ways to get a user object.  One involves a straight spW.SiteUsers.Add(…… lots of data)

the other uses the Microsoft.Office.Workflow.Utility and generates a Contact, then uses this to get the actual user object. 

Contact contact=Contact.FromName(userloginname,spW);
if(contact.PrincipalID < 0){
     //this actually adds the user to the site collection users list
     SPPrincipal p=contact.GetPrincipal(spW);
}
SPUser owner=spW.SiteUsers[contact.LoginName];
spW.SiteGroups.Add(spW.Title + " Owners",owner,null,"This is the default owners group")
SPGroup grpOwner=spW.SiteGroups[spW.Title + " Owners"];
spW.AssociatedOwnerGroup=grpOwner
//Repeat for other groups

Finally set the group permissions

SPRoleDefinitionCollection roleDef=spW.RoleDefinitions;
SPRoleAssignmentCollection roleAssigns=spW.RoleAssignments;
SPRoleAssignment roleAssign = new SPRoleAssignment(grpOwner);
SPRoleDefinitionBindingCollection definitions=roleAssign.RoleDefinitionBindings;
definitions.Add(roleDef["Full Control"]); //Could be Contribute or Read
roleAssigns.Add(roleAssign);
//Repeat for other groups
spW.Update();

Posted in Sharepoint | Tagged: , , , , , , , , , , , , , , | 3 Comments »

 
Follow

Get every new post delivered to your Inbox.