SPWorkflowTaskProperties.ExtendedProperties aren’t populating the fields in my task - sharepoint

I am attempting to pass information from a task created within a workflow to its corresponding task form. Prior to the CreateTask activity, I create an SPWorkflowTaskProperties and fill it with the usual info (title, assigned-to, etc). I also add some elements to the ExtendedProperties property. However, those custom properties never make it into the Task.
I've tried setting the property key to:
the Guid of one of my task' content
type's fields;
the internal name of
one of my task' content type's
fields;
an unrelated name (in the
hopes of getting the info into the
task's properties instead of its
fields).
Nothing works. The task, once created, contains only the built-in field values I have set. None of values I explicitly added to the extended properties show up.
The (simplified) sequence of my activities is as follows:
PrepareTask. This is a custom
activity that contains the
SPWorkflowTaskProperties
CreateTask. The task properties are bound to the one in the PrepareTask activity.
OnTaskCreated. The task properties are bound to the one in the PrepareTask activity.
While (task not complete)
OnTaskChanged
I am using WSS 3.0 SP1 and an ASPX (NOT InfoPath) task form.

I still don't know why my original solution didn't work. But I have found a workaround. My sequence of activities is now:
CreateTask
OnTaskCreated
CopyTaskItems. This is a custom
activity that puts values into my
custom task's fields, then updates
the task.
While (task not complete)
OnTaskChanged
So I have to create the task, then immediately poke values into it and update.
I hope this will help some future reader of this question.

You should be using a ItemMetadata.xml document as a secondary datasource that contains the definition of the fields that you want to pass to your task form. Something like:
<z:row xmlns:z="#RowsetSchema"
ows_Instructions=""
ows_Body=""
ows_Comments=""
ows_ApprovalStatus=""
/>
The File name is important btw.
Notice the ows_ (as it used the webservices all fields in the list will be prefixed with ows.)
Then in you infopath form, set the default value of each control you want to display this information in. Hit the fx button and insert a field or group from the secondary datasource.
A good resource: http://weblog.vb-tech.com/nick/archive/2007/02/25/2207.aspx

Related

CRM 2011 Workflow not triggered before mandatory fields are checked

I am looking to create a workflow that will populate any mandatory fields that do not contain data when a company is deactivated. The mandatory fields are either not populated because of legacy data or because the mandatory fields have changed since the record was created.
The issue I get is that the mandatory field check takes place before the workflow is triggered.
My workflow looks like follows:
If Status = Inactive
If Company Name does not contain data
Then update to ‘Test’
I have come up with a possible solution:
• Create a new button in the ribbon that runs the workflow on-demand and apply permissions to this button.
If possible though I would like to do this through a workflow that is triggered on clicking of the ‘Deactivate’ button. Any ideas are welcome.
In your situation the record will not be saved until the mandatory fields are filled, and a workflow cannot be triggered if a record is not saved first.
An approach to solve this situation is to write a JavaScript attached to the OnSave event, but you need a rule to be able to identify the legacy records, so this JavaScript (that will fill the mandatory fields for you) will not run for normal records.
This approach is not tested, but with some tweaks should work.

MS CRM 2011 - Changing UI label for custom CodeActivity

I call the same custom CodeActivity a number of times in a workflow with different input parameters, and then follow each call with a Check Condition step against the output parameters.
The problem is there is nothing in the UI to distinguish between the calls. At the moment I just keep selecting the last on in the drop down under Local Values hoping that was the most recent call.
Is there someway to override what the UI shows, e.g. a property of the CodeActivity I can override to include the value of an input parameter. I've been through the reference page and nothing specifically claims to do this. Normally I would just play around to see what happens but not being that familiar with CRM I'm afraid I'm going to break something big time.
Yes: you can put a description on each activity in the workflow designer. By default it says "Type the step description here." If you type a description, this description will be used as the name of that activity in later steps.

Defaulting parent entity of custom activity

This should be a simple thing, but as I am quickly finding out with CRM 2011, simple things almost never are...
Anyway, I have a custom activity type, a "Trip". A Trip represents a single visit by a service technician to a client's site. Trips are always created in connection with a Case (Incident) and never with any other entity type, so the entity exists as a custom activity that does not "Display In Activity Menus". That allows me to drop a subgrid of Trips into the primary Case view, making it the only place these things can be created.
The problem is that when I try to create a new Trip from the Case form (by clicking the subgrid and choosing "Add New Trip" from the ribbon), the "Regarding" field isn't populated with the Case that I was on when I clicked "Add". Any of the "built-in" activity types will default their corresponding field with no problem, so it would seem to me that I can do the same here. The field's supposed to be read-only once this defaulting works, but just so I can set up the reference when creating new Trips, I've made it editable, and of course when you pop up the lookup, you can assign this Trip to anything (which is why I want the field read-only in the first place).
I need the form to default the parent Case when the Trip form loads. It has to be there when it's first created, because if it isn't there on the first save, then some plugin code that sets other default values (namely data relating to other Trips that may or may not exist for the same Case) won't work properly.
I read about relationship field mapping, where you can default the values of various fields based on fields of the parent entity, but the relationship between the Incident and my Trip is not listed as mappable from either side and I can't figure out how to make it mappable. I also know it's possible to set default values using JavaScript, but if there's a less "custom" way to set this particular behavior up I would love to know how.
As an epitaph based on Mike's comment, it does indeed seem that Microsoft doesn't want this done. But, it's still possible to do it. The basic steps are:
Download the Ribbon Workbench solution and import it into CRM.
Create a new solution containing the entity or entities you want to be able to customize.
Create a JavaScript file containing functions that will open the form you want and pass the information you need as a parameter. There are two ways to specify the parameters; you can define custom parameters on the form, or you can use Microsoft's undocumented parameters for the Regarding field:
function OpenNewTripFromCase()
{
var entityId = Xrm.Page.data.entity.getId();
var entityTypeCode= Xrm.Page.context.getQueryStringParameters().etc;
var entityDisplayName = Xrm.Page.getAttribute("title").getValue();
var params = {};
params["pId"] = entityId;
params["pType"] = entityTypeCode;
params["pName"] = entityDisplayName;
Xrm.Utility.openEntityForm("cst_trip", null, params);
}
Import this JavaScript file as a Web Resource, and add it to the Solution so it will be available to Ribbon Workbench.
Open up Ribbon Workbench and open the solution you created with your entity and resources. Click the Solution Elements tab, and find the "Commands" item. Right-click and select "Add New". Now expand the list, find and click on your new command. In the Properties pane, change the name of the command to be more descriptive (it's recommended you only change the third "Command#" term), then click the magnifying glass button to the right of the Actions field.
In the window that pops up, click "Add", then choose "JavaScript Function Action". A new item will be added to the action list. Click it, then in the properties pane to the right, find the library containing your function, then type in the function name. I didn't get any sort of IntelliSense here, so be careful typing in the function name. Add parameters if you need to (you shouldn't need to with the code above), then click OK
Now click the custom activity entity in the Entities list of Ribbon Workbench, then in the dropdown to the upper right of the ribbon layout, select the SubGrid ribbon. Create a button in this Ribbon, give it the icon and text you want, and in the Properties pane, set the Command to the command you just created.
Publish the customized Solution, and you should, if you did everything correctly, have a new button that will do the same thing as the "Add New" button when you've selected a sub-grid, but will additionally populate the Regarding field.

How should I implement `OnLoad` event handler when creating an activity using a contact?

I've created my own solution with a custom entity of type activity. I'd like to show a message whenever a new instance of it is created using an existing contact but not allow the user to create one, if only attempting to do that without going via contact.
Basically, my aim is that it won't be impossible to just create that activity (the form will be hidden directly at any attempt except for one way only). The user will have to go to contacts (or leads etc.) and in there add and create an instance of the custom activity entity. That way, I can assure that the field "regarding" will be filled out already.
I'm guessing that I need to detect somehow that the opening of the form is a creation attempt. How can I do that?
Also, as it is now, the user can't create a contact-less activity of the custom type because it doesn't appear on the menu with other activities. I must have disabled it somehow but I have no idea how. Anybody who has one?
You could do this a bunch of ways but the easiest would probably be to:
Make the regarding field read only.
Make the regarding field mandatory.
That way if a user opens a create new form they wont be able to set the regarding and because its mandatory they wont be able to save the record. When they open via an existing contact the regarding field will be mapped automatically. That said in this case just making it mandatory my be enough.
(As a side JavaScript can be used to identify the current form state, but I'm not sure how useful that is here).
In terms of where custom activities appear, by default mine show in a number of locations, for example:
CRM > Workplace > Activities > Ribbon > Other Activities > XXX.
CRM > Workplace > Activities > View Selector > XXX.
They don't show under the left hand navigation of the workplace because they are grouped under 'Activities'. I'm pretty sure these are all the default settings.
You can exercise greater control by editing the sitemap, where you can put pretty much anything, anywhere.
In addition to Mr Wood, I'd like to show you some code. It works as supposed to but I'm not sure if it's optimal.
var foo = function () {
var whatIsGoingOn = Xrm.Page.ui.getFormType();
if (whatIsGoingOn === 1)
alert("Let there be an entity!");
else
alert("Not a creation...");
}
The other states' (deletion, update etc.) numeric values are listed here.
Answering the second part of your question:
When you create a custom activity you can choose whether to have it appear in 'normal' Activity menus or not by checking the box at the top right of the entity form. This is a once-only choice as far as I know and can't be changed later.
For your setup, I would suggest NOT checking this box, so it does not appear in the activity menus to avoid users even being tempted to do it that way.
Instead, add an explicit relationship to the activity N:1 to Contact, and another N:1 to Lead. Use this relationship to add your activity to the left navigation of Contact and Lead forms, or add a grid for them (depends on how you want to use this and if you need to filter the view to something other than the default "Associated View").
When a user navigates to this section they will see if any previous activities of this type exist, and be able to add a new one. BUT this means that the child record is a child via this relationship, not using "regarding", so use a script on the form for the activity so that if Contact is filled in, it is copied to Regarding, and if Lead is filled in then that is copied. If neither, then use an alert or other means to warn the use that something is wrong (see comment earlier). If you want Regarding to be read-only but filled in by script, you will need to make sure to use the force the value to be saved:
Xrm.Page.getAttribute("regardingobjectid").setSubmitMode("always");
You must have the lookups for Contact and Lead on the form to be able to use them in your scripts, but you can make them not "visible by default" so they are there but not seen by the user (and taking up no space).

SharePoint Worflow Extended Propoerties do not retain its value after the workflow task is changed

I am using SharePoint 2010 Workflow where i have created couple of Task Edit Forms in Infopaht 2010.
Here is the reference of how i am specifying extended property value in TaskEdit form from the SharePoint Workflow. Similar to the refrence article, In my TaskEdit Form also i have one Text box whose value i specified as extended property from my workflow.
My Problem is that once a workflow task is created the extended propery is properly displayed in the task edit form, but when the user changes the task that point onward if the user agains opens his assigned workflow task, the extended property value is not retained. It appears blank.
Here is how I am specifying the extended property from my workflow's CreateTask activity.
SPWorkflowTaskProperties wtp = new SPWorkflowTaskProperties();
wtp.ExtendedProperties["ExtendedPropertyField"] = "Some text value";
Do i have to reset it somewhere on task changed event ? Am i missing something here ? Any idea ?
Thanks.
Yes I think it should be reset/retained in the on task changed activity.
Check if the field is retained during this event
public SPWorkflowTaskProperties onTaskChanged1_AfterProperties = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
string field_value=onTaskChanged1_AfterProperties.ExtendedProperties["ExtendedPropertyField"].ToString();
field_value should not be null.
Thanks

Resources