I am using SharePoint Foundation (Sharepoint 2010) to develop a workflow in Visual Studio with an ASP.NET Workflow Initiation Form.
I use this form to set some properties on the share point list item on which the workflow instance is being started. Sometimes I get an Error message in the brwoser window, something like:
Error
Failed%20to%20Start%20Workflow
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 0b8e0b67-f824-4aa5-8316-424ada134f8d
Date and Time: 6/25/2010 10:59:17 AM
Go back to site
This behaviour seems intermittent. What's going on?
The problem is that the SharePoint workflow initiation form caches the workflow List Item on PageLoad, and when you make changes to the item between the page load and calling HandleStartWorkflow (i.e. clicking on the Start Workflow button), SharePoint freaks out that the item that you're talking about is different (the cached item) to the item that exists in Share Point (which incorporates the changes you've just made).
The general steps to reproduce the problem are:
Start the workflow so that the initiation form shows.
Change some property on the WorkflowProperties.Item
Call WorkflowProperties.Item.Update to save the changes to SharePoint
Call HandleStartWorkflow.
You will get the error.
The error may seem intermittent if some of the time the change to the workflow item properties is made in a separate page load 'session' to the session that the Start Workflow button is clicked. For example, if you PostBack some form data and then click the Start workflow button then everything works, because the PostBack happened and then the page was loaded.
But if you use an ASP TextBox OnTextChanged event, change the text and then click the Start Workflow button, the OnChanged event is fired AFTER the page is loaded with the old data, the data is changed to the new data and the workflow is started before the item data is re-loaded from SharePoint.
The fix is easy: Reload the workflow item data JUST before starting the workflow. This will cause your cached workflow item and the sharepoint version of the item to be the same, and share point will be happy.
In the "Workflow Initiation Code" region, change:
Private Sub StartListWorkflow()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
to
Private Sub StartListWorkflow()
'Re-initialize the workflow parameters, particularly the workflowListItem, in case it has been changed since page load.'
InitializeParams()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
And everything should start working again.
The same message you will get if you try to start workflow (through the custom init form) which is already running on the item. Solution here would be to check the state of the workflow on the item.
Related
I'm creating a custom form for appointments in Outlook for a project (add catering request to a meeting) - this is my first rodeo at doing this - and I'm striking out big time regardless of my intense (and failing) Google-Fu.
With a new appointment open, on the developer tab, I select "Design This Form". I go to tab "(P.2)" and build a stupid-simple, two-object form... CheckBox1 and TextBox1. In properties, TextBox1.Visible is False. Click View Code and input the following...
Private Sub CheckBox1_Click()
if CheckBox1.value=True Then
Me.TextBox1.Visible = True
Else Me.TextBox1.Visible = False
End If
End sub
I then click "Run This Form" and see/click CheckBox1 but nothing happens. If I could make this run, I might be in business. But it won't. So, I look for a work-around.
Grasping at straws, I open "Visual Basic" and basically do the same thing - create a form "UserForm1" with the same two objects and add the same code. Click the go-button and it works as expected. The TextBox1 appears and disappears with the CheckBox1 state.
As I can make the code function, I would build everything I need in the Visual Basic editor, however... Here's the problem - I have absolutely no idea how to get the form I create here into the Outlook application as a tab or button or whatever. I basically want the custom form VBA editor to be a selectable option in any Appointment.
I have watched tutorials, read doc, saw something about creating a macro - but nothing was written/stated dumbed-down enough for me to follow.
So my question: How do I get the UserForm1 that's built in VBA Editor to appear in a New Appointment when a button is clicked in Outlook?
You need to add the Click event handler for the CheckBox control, not just paste the code to your custom form.
Following the June 13 2017 security update, users discovered published custom forms no longer worked because VBScript behind the form and some controls are blocked by default. See Custom Form Security Changes and Custom form script is now disabled by default for more information.
Microsoft disabled custom form script functionality. If you need it enabled, you'll need to set two keys, one to enable scripting and a second one with the message class name of each form that has code behind it. For example:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Security
DWORD: DisableCustomFormItemScript
Value: 0 (to enable)
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\16.0\Outlook\Forms\TrustedFormScriptList
REG_SZ: IPM.Contact.custom-form-name
Value: (leave blank)
In some cases, forms in secondary mailboxes and Public folders still don't work after the registry key settings. To fix this, enable scripts in the Trust Center:
Click File > Options. Then select Trust Center > Trust Center Settings > Email Security.
Under the Script in Folders section, click the checkbox for Allow script in shared folders and Allow script in Public folders and click OK and OK again to close out the windows.
I have a visual web part (sandboxed) that visualize a form for adding sub-sites. When a sub-site is added its added in the navigation and in a DropDownlist (for delete purpose...).
My problem is that after post-back everything works fine, except i have to manually reload the page to see the new changes (both nav. and dropdownlist). Note that neither Response.Redirect or UpdatePanel will work i a sandboxed-solution.
Anyone got a solution to this problem?
When you perform a postback, your browser submits the contents of all web controls to the server. The server is stateless in this sense; the state of the control is actually stored in your browser. I would say your problem occurs because the web controls are not populated from SharePoint object model. Instead, the server uses the data received as the postback. Alternatively, the population might even happen, but the postback data will overwrite the contents of controls.
The solution is to refresh control data after the controls have been populated from the postback data. You could do this, for example, in the method OnPreRender. When OnPreRender is called, all the postback data has already been processed.
Try to add the following code in your webpart class.
protected override void OnPreRender(EventArgs args)
{
if (this.Page.IsPostBack)
{
// Repopulate controls here
}
}
The problem of this is, of course, that repopulation will kill the previous (postback) state of the controls. So, if you want to preserve the current value of a control (such as a dropdown selection), you must save it before repopulation and restore it manually.
To learn more about the page lifecycle in ASP.NET, see ASP.NET Page Life Cycle Overview.
I have written a report in asp.net MVC 3 with the report viewer using a user control (ascx) in a partial View in the Report.cshtml(View). I'm having a problem with report viewer control when I run the application. When I have more than two pages and I want see the second or more page, I get "microsoft jscript runtime error '__eventtarget' is null or not an object".
The error is because there is postback. How can I fix this?
You're not going to be able to use the built in toolbar to navigate. (At least not without finding your own work around).
What I did was created my own bar right above my control and it simply sends an action ("First", "Last", "Next", "Previous") to an action on the controller to adjust the ReportViewer's CurrentPage Variable. (I keep tract of the current page through the session and set it in the user control ascx).
I have created associations between entities in my .Net assembly BCS model. When I load the model into SharePoint and create external lists, I automatically get an External Item Picker control; enabling me to select an item from a list.
This is great because I don't have to program this pick list one way or another...
The problem is whenever I modify the form in InfoPath, the External Item Picker seems to break. When I select an item using the External Item Picker (in the InfoPath form) I get an error message "There has been an error while processing the form". This message is displayed as soon as I select an item and try to leave the field; WITHOUT submitting the form.
Can anyone tell me why the External Item Picker breaks whenever I modify and publish the list form from InfoPath 2010?
It's driving me nuts!
Thanks!
I've ran into the same issue, and found the following answer:
It's a bug from the August cumulative update.
Source
I am in the process of installing the February CU to see if it has the solution.
I am building a visual web part which has a number of user-configurable properties. The web part will display news items and, optionally, automatically switch to the next item after a defined pause.
The problem I'm having is that the user control part has a timer which fires events. These events reenter the user control (without going through the web part) and I see that when this happens the user control is in an unitialised state - i.e. the custom properties of the web part have not been applied. This causes the control to behave in it's default manner.
What am I doing wrong?
When you set property in your webPart, you need to bubble it down to the User control.
See creating custom properties for visual webparts:
http://patricklamber.blogspot.com/2010/05/how-do-i-create-custom-properties-in.html