Archive for July, 2009

20
Jul
09

#30 Sharepoint: Accessing a Site Collection\SPWeb within a Workflow and updating a list

Below I am grabbing data off a Workflow with a browser enabled Infopath Form and loading a separate list.


public Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties workflowProperties = new Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties(); 

  private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {

              ...
                //Save the identifier for the workflow
                workflowId = workflowProperties.WorkflowId;

                // InitiationData comes from the initialization form
                XmlDocument document = new XmlDocument();
                document.LoadXml(workflowProperties.InitiationData);

                // Get Data Off Of Init Form
                XmlNamespaceManager ns = new XmlNamespaceManager(document.NameTable);
                ns.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-05T20:04:17");
                managerUsername = document.SelectSingleNode("/my:flowFields/my:managerUsername", ns).InnerText;
                managerFullname = document.SelectSingleNode("/my:flowFields/my:managerFullname", ns).InnerText;
                reviewType = document.SelectSingleNode("/my:flowFields/my:reviewType", ns).InnerText;
                reviewComments = document.SelectSingleNode("/my:flowFields/my:reviewComments", ns).InnerText; 

                using (SPSite siteCollection = workflowProperties.Site)
                {
                    using (SPWeb web = siteCollection.OpenWeb())
                    {
                        SPList EmployeeReviewList = (SPList)web.Lists["EmployeeReview"];                     // Specific List
                        SPListItem EmployeeReviewItem = OptimizedAddItem(EmployeeReviewList);       // Add New Item to List
                        EmployeeReviewItem["Review Name"] = reviewType;                                            // Update elements of new item
                        EmployeeReviewItem.Update();
                    }
                }  

  ... }

       //cf.  http://blog.robgarrett.com/2009/02/25/efficient-way-to-add-a-new-item-to-a-sharepoint-list
        public  SPListItem OptimizedAddItem(SPList list)
        {
            const string EmptyQuery = "0";
            SPQuery q = new SPQuery { Query = EmptyQuery };
            return list.GetItems(q).Add();
        }

Credit due for OptimizedAddItem(): http://blog.robgarrett.com/2009/02/25/efficient-way-to-add-a-new-item-to-a-sharepoint-list/

15
Jul
09

#29 PopUp under Deltek 6.x Smart Client

The issue is that by running a smart client an iframe or window open launches a browser window separate from the smart client which is a Windows client executable & not a browser app. Since that is unavoidable using a modal window with target self tag in the head works best. This method will however still leave the initial help window open in the smart client.

Add the Help Icon ? and replace the Help Text (directly via a control-V paste do not click on ellipse to launch editor) with:

<script>javascript:  window.showModalDialog("http://targetpage.aspx",'_parent', "dialogHeight: 200px;");</script>

In your target page (html or aspx) since this is a modal window this will ‘correct’ any postbacks from launching a new window.

<HTML>
                <HEAD>
                                <base target="_self" />
 ...

Put a button with a OnClick event to close this popup. The window.opener=’X';window.open(”,’_parent’,”);window.close(); will avoid the usual warning.

Credit Due on avoiding the window close warning: http://blogs.x2line.com/al/articles/350.aspx

					function CopyToClipboard()
					{
						document.frmVisible.txtJobNumber.focus();
						document.frmVisible.txtJobNumber.select();
						CopiedTxt = document.selection.createRange();
						CopiedTxt.execCommand("Copy");
						alert('Number has been copied. Use Control-V to paste into new project screen.');
						window.opener='X';window.open('','_parent','');window.close();
					}

cf . http://dmgorman.wordpress.com/2008/01/11/02-simple-popup-help-page/