Collect Data from a User and Set Workflow Variable action in SharePoint Designer


The step by step instruction can be found at the below link

https://nishantrana.me/wp-content/uploads/2009/01/sharepoint.doc

Bye…

Building a simple workflow with Visual Studio 2005 in SharePoint


Create a new SharePoint Sequential Workflow project.

Drag and drop SendEmail activity just after onWorkflowActivated1 activity .

Set CorrelationToken property of SendEmail to workflowToken which is the workflow correlation token used by onWorkflowActivated1.

For MethodInvoking set the value sendEmail1_MethodInvoking and click which would generate the handler.

private void sendEmail1_MethodInvoking(object sender, EventArgs e)

{

sendEmail1.To = “myId@g.com”;

sendEmail1.From = ” myId@g.com “;

sendEmail1.CC = ” otherId@g.com “;

sendEmail1.Subject = “MySubject”;

sendEmail1.Body = ” This is test mail”;

}

}

Strong sign the assembly and install it in GAC.

Set your feature.xml as following

<Feature Id=23CB845A-7204-4d41-9873-FE50BEB78BCD

Title=Default Title

Description=This feature is a workflow that …

Version=12.0.0.0

Scope=Site

xmlns=http://schemas.microsoft.com/sharepoint/>

<ElementManifests>

<ElementManifest Location=workflow.xml />

</ElementManifests>

</Feature>

Id– Provide a new guid for uniquely identifying the feature

Title – to be displayed in the list of features deployed to the site

Description – Any description that appears beneath the Title.

Location – Leave it to default as the directory is same.

Set your workflow.xml as following

<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<Workflow

Name=My Workflow

Description=This workflow …

Id=049971BB-5BAA-4bf1-98A2-747675A18DCB

CodeBesideClass=SharePointWorkflowLibrary3.Workflow1

CodeBesideAssembly=SharePointWorkflowLibrary3, Version=1.0.0.0, Culture=neutral, PublicKeyToken=58efe34bdb2df93e

>

<Categories/>

<MetaData>

<StatusPageUrl>_layouts/WrkStat.aspx</StatusPageUrl>

</MetaData>

</Workflow>

</Elements>

Name – Name of the workflow.

Description – Any description about the workflow

Id – A new guid for the workflow

CodeBesideClass – Namespace.ClassName

CodeBesideAssembly – name of assembly, version , culture and publicKeyToken which we can get by right clicking the assembly in gac and selecting properties.

Remove all other entries as we are not using any forms for this workflow.

Now modify the install.bat file as mentioned in the instruction for the same.

Run install.bat

Next go to the site where the new workflow has been deployed.

Select any document library – than settings- document library settings – workflow settings – add a workflow.

We’ll see our workflow within the workflow template.

Correlation Token – A correlation token is essentially a means of uniquely identityfing each instance of a workflow, modification or task.

Bye…

SetState for CustomEntity in CRM


For every new custom entity created in CRM corresponding SetStateCustomEntityNameRequest and SetStateCustomEntityNameResponse class gets created which we can use to set their status.

 

In the below example we have set the status inactive for our custom country entity records.

 

 

 SetStateNew_CountryRequest myCountryRequest = new SetStateNew_CountryRequest();

                // guid of the record to be deactivated

                myCountryRequest.EntityId = new Guid(“3AE10D22-60E4-DD11-9D85-00164145E126”);

                // statecode – 1 , statecodename- Inactive, statuscode – 2, statuscodename – Inactive

                // statecode – 0 , statecodename- Inactive, statuscode – 1, statuscodename – Inactive

                myCountryRequest.New_CountryState = New_CountryState.Inactive;

                myCountryRequest.New_CountryStatus = 2;

                SetStateNew_CountryResponse myCountryResponse = (SetStateNew_CountryResponse)crmService.Execute(myCountryRequest);

 

Bye ..

Understanding and Using AJAX


Suppose this is our simple ASP.NET page i.e. MyPage.aspx which would be called using AJAX

Code for MyPage.aspx.cs

protected void Page_Load(object sender, EventArgs e)

{

// no data is passed

if (Request.QueryString[“myGetData”] == null)

{

Response.Write(“Hello World”);

}

// if GET method is used to call this page

else if (Request.QueryString[“myGetData”] != null)

{

Response.Write(“Hello “ + Request.QueryString[“name”].ToString());

}

// if POST method is used to call this page

else if (Request.Form[“myPostData”] != null)

{

Response.Write(“My Post Data is “ + Request.Form[“myPostData”].ToString());

}

}

Delete everything from MyPage.aspx page just keep the page directive otherwise html tags would also be sent as a part of response.

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Mypage.aspx.cs” Inherits=”MyPage” %>

Now the javascript code to call the page asynchronously using AJAX. Comment/Uncomment the particular section of code to test the functionality

<script type=”text/javascript”>

var request=null;

function CreateRequest()

{

try

{

// create a new object to talk HTTP with a web server.

// XMLHttpRequest – works on Safari,Firefox, Mozilla, Opera , IE 7 and most other browsers

request=new XMLHttpRequest();

}

catch(trymicrosoft)

{

try

{

// Msxml2.XMLHTTP – Most version of IE support this

request=new ActiveXObject(“Msxml2.XMLHTTP”);

}

catch(othermicrosoft)

{

try

{

//Microsoft.XMLHTTP – but for some, we’ll need this other type

request=new ActiveXObject(“Microsoft.XMLHTTP”);

}

catch(failed)

{

request=null;

}

}

}

if(request==null)

alert(‘Error creating request object’);

else

{

// i.e. space with %20

// if no data is to be send

var url=“MyPage.aspx”;

// open-initialize the connection

// GET – specify how to send data to the server

// url- url to send the request

// asynchrounous – true

request.open(“GET”,url,true);

// telling the browser what to do with the server’s response

// i.e. the function to be called when response is received

// onreadystatechange- this property affects every ready state not just the one indicating

// that the server is finished with request

request.onreadystatechange=updatepage;

// send the request

// no data is required so send null

// for using send() to pass data to a server requires POST method for the request and need to specify content type

request.send(null);

// if data is to be send using GET i.e. as query string

var name=“MyName”;

// escape() function replaces characters like space with something that will work as a part of a request URL.

var url=“MyPage.aspx?myGetData=”+escape(name);

request.open(“GET”,url,true);

request.onreadystatechange=updatepage;

request.send(null);

// if more data is to be send than use post

var name=“MyName”;

var url=“MyPage.aspx”;

request.open(“POST”,url,true);

request.onreadystatechange=updatepage;

//setRequestHeader()- allows us to add information to the request usual intended for use by the server

// Content-Type – is the name of the request header

// application/x-www-form-urlencoded – the value of the request header

// this tells the server that the data is encoded like it would be in a request URL

// for passing XML content replace “application/x-www-form-urlencoded” with “text\xml”

request.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded”);

// specify the data to be send

// escape() function replaces characters like space with something that will work as a part of a request URL.

request.send(“myPostData=”+escape(name));

}

}

// updatepage – this function will get run every time the ready state changes

function updatepage()

{

// readyState=this property of the request object stores the current state

// if 4 means server is done with the request

// if 0 i.e uninitialized

// if 1 i.e open, the object has been created but the send method has not been called

// if 2 i.e. sent, the send method has been called.

// if 3 i.e. receiving , responseText is not available but some data has been received

// if 4 i.e. loaded, all the data has been received, responseText is available

if(request.readyState==4)

{

// check for the status send by the server

// if 200 i.e. everything is fine

// if 404 i.e. if the page specified in the url is not found

if(request.status==200)

{

var myResponse=request.responseText;

alert(myResponse);

}

else

{

alert(“Error! Request status is “ +request.status);

}

}

}

</script>

<input id=”Button1″ type=”button” value=”button” onclick=”CreateRequest()”/>

Bye…

Programmatically updating the status of workflow logs using TargetUpdateWorkflowLog class in CRM 4.0


I was just trying out if changing the status for the workflow is possible programmatically. Well this is something I tried.

Created a function which would take primary key(guid) of the entity intance and would return all the workflow logs for that entity instance having status as “In Progress” and changing their status to “Failed”

 

The function to retrieve all the workflowlog id

 

private ArrayList   GetInProgressWorkflowLogIDForEntity(CrmService crmService, string EntityId)

        {

            QueryExpression myQuery = new QueryExpression();

            ColumnSet myCols = new ColumnSet();

            // to retireve workflowlogid

            myCols.Attributes = new String[] { “workflowlogid” };

            myQuery.ColumnSet = myCols;

            myQuery.EntityName = EntityName.workflowlog.ToString();

          

            ConditionExpression myCondtionExpression1 = new ConditionExpression();

            // entityinstance id against which workflowlog is running

            myCondtionExpression1.AttributeName = “regardingobjectid”;

            myCondtionExpression1.Operator = ConditionOperator.Equal;

            myCondtionExpression1.Values = new object[] {EntityId };

            // Status of workflowlog

            // Failed – 3

            // Succeeded – 2

            // In Progress – 1

            ConditionExpression myCondtionExpression2 = new ConditionExpression();

            myCondtionExpression2.AttributeName = “In Progress”;

            myCondtionExpression2.Operator = ConditionOperator.Equal;

            myCondtionExpression2.Values = new object[] { “1” };

 

            FilterExpression myFilterExpression = new FilterExpression();

            myFilterExpression.FilterOperator = LogicalOperator.And;

            myFilterExpression.Conditions = new ConditionExpression[] { myCondtionExpression1, myCondtionExpression2 };

 

            myQuery.Criteria = myFilterExpression;

 

            BusinessEntityCollection myBE=crmService.RetrieveMultiple(myQuery);

 

            ArrayList myWFLogList = new ArrayList();

            foreach (BusinessEntity myBusinessEntity in myBE.BusinessEntities)

            {

                workflowlog myWFLogId = (workflowlog)myBusinessEntity;

                myWFLogList.Add(myWFLogId.workflowlogid.Value.ToString());

 

            }

            return myWFLogList;    

        }

 

 

 

 

Using TargetUpdateWorkflowLog class

 

 

ArrayList myWorkflowLog=GetInProgressWorkflowLogIDForEntity(crmService, “55B93CBB-99E3-DD11-9D85-00164145E126”);

 

                foreach (String wfLogId in myWorkflowLog)

                {

                    TargetUpdateWorkflowLog myUpdateWorkflow = new TargetUpdateWorkflowLog();

                    myUpdateWorkflow.WorkflowLog = new workflowlog();

                    myUpdateWorkflow.WorkflowLog.workflowlogid = new Key();

                    // workflowlogid of workflow having status as In Progress

                    // to be changed to Failed – 3

                    myUpdateWorkflow.WorkflowLog.workflowlogid.Value = new Guid(wfLogId);

 

                    // Failed – 3

                    // Succeeded – 2

                    // In Progress – 1

                    myUpdateWorkflow.WorkflowLog.status = new Picklist();

                    myUpdateWorkflow.WorkflowLog.status.name = “Failed”;

                    myUpdateWorkflow.WorkflowLog.status.Value = 3;

 

                    UpdateRequest myRequest = new UpdateRequest();

                    myRequest.Target = myUpdateWorkflow;

 

                    UpdateResponse myRes = (UpdateResponse)crmService.Execute(myRequest);

                }

           

Understanding inputparameters and outputparameters of plugin context in CRM4.0


I was wondering what inputparameters and outparameters are passed by the platform to the IPluginExecutionContext’s context. Just created a simple plugin and registered it for (Pre/Post)Create,Update, Delete event of lead. And debugged it in visual studio to know the values for these parameters

InputParameters will have the parameters of the request message whi ch triggered the event i.e Represents the data that was passed along with the request to the platform. It will have two keys Target and OptionalParameters

Target property will be passed as a DynamicEntity and represents the image of the data passed.

OutputParameters is populated by the platform and only contains valid data during the After

Operation stage. This will contain the properties of the response message. The most common property returned is an “id” entry that will represent the Guid. In that example, it works exactly the same way the Request will produce a Response object with an id property. You would use this value to do subsequent processing that you need the entity Id value to be able to relate data.

OutputParameters will have the properties of the response message which is returned as part of pipeline execution. It will have one key OptionalParameters.

For PreCreate

Inputparameters – Two key – Target and OptionalParameters

Target – It had 35 properties basically one for all the attributes with its corresponding values

For optional parameters it had following value
CreateDuplicatesOptionalParameters with the value as false.

For PostCreate.

InputParameters – Target – same 35 properties for each attribute.

OutputParameters – Had one key – id with values of the newly created lead.

For PreUpdate

InputParameters – It had attributes whose values have been modified , leadid (primarykey of lead) as well those attributes that have forceSubmit true.

CreateDuplicatesOptionalParameters with the value as false.

Outputparameters – Nothing in output parameters

For PostUpdate

InputParameters – It had attributes whose values have changed, leadid (primarykey of lead), as well those attributes that have forceSubmit true.

CreateDuplicatesOptionalParameters with the value as false.

Outputparameters – Nothing in output parameters.

For PreDelete

Target was of type -Microsoft.Crm.Sdk.Moniker having Id of the record to be deleted and name as entity name – lead

For create,update message Target property was -Microsoft.Crm.Sdk.DynamicEntity.

Nothing in OptionalParameters

Outputparameters – Nothing in output parameters.

For PostDelete

Target was of type –Microsoft.Crm.Sdk.Moniker having Id of the record to be deleted and name as lead

Nothing in OptionalParameters

Outputparameters – Nothing in output parameters.

 

To know more about inputparameters and outputparameters

http://www.patrickverbeeten.com/pages/ContentItemPage.aspx?id=12&item=53&p=true

Bye..

Advertisements