Skip to main content

SharePoint Nintex Workflow Custom Actions developments using server side object model

Read FromProperty Activity
-
------------------------------------------------------------------------------------------------------------------------

using System;
using System.Workflow.ComponentModel;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Nintex.Workflow;
using Microsoft.SharePoint;

namespace CFSP.CustomActions.ReadFromPropertyBag
{
    public class ReadFromPropertyBagActivity : Nintex.Workflow.Activities.ProgressTrackingActivity
    {
        public static DependencyProperty __ListItemProperty = DependencyProperty.Register("__ListItem", typeof (SPItemKey), typeof (ReadFromPropertyBagActivity));
        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof (WorkflowContext), typeof (ReadFromPropertyBagActivity));
        public static DependencyProperty __ListIdProperty = DependencyProperty.Register("__ListId", typeof (string),typeof (ReadFromPropertyBagActivity));
        public static DependencyProperty WebProperty = DependencyProperty.Register("Web", typeof(string), typeof(ReadFromPropertyBagActivity));
        public static DependencyProperty PropertyProperty = DependencyProperty.Register("Property", typeof (string), typeof (ReadFromPropertyBagActivity));
        public static DependencyProperty ResultOutputProperty = DependencyProperty.Register("ResultOutput", typeof (string), typeof (ReadFromPropertyBagActivity));

        public WorkflowContext __Context
        {
            get { return (WorkflowContext) base.GetValue(__ContextProperty); }
            set { base.SetValue(__ContextProperty, value); }
        }

        public SPItemKey __ListItem
        {
            get { return (SPItemKey) base.GetValue(__ListItemProperty); }
            set { base.SetValue(__ListItemProperty, value); }
        }

        public string __ListId
        {
            get { return (string) base.GetValue(__ListIdProperty); }
            set { base.SetValue(__ListIdProperty, value);}
        }

        public string Web
        {
            get { return (string) base.GetValue(WebProperty); }
            set { base.SetValue(WebProperty, value);}
        }

        public string Property
        {
            get { return (string) base.GetValue(PropertyProperty); }
            set { base.SetValue(PropertyProperty, value);}
        }

        public string ResultOutput
        {
            get { return (string) base.GetValue(ResultOutputProperty); }
            set {base.SetValue(ResultOutputProperty, value);}
        }

        public ReadFromPropertyBagActivity()
        {

        }

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            //Standard Nintex code to obtain context.
            ActivityActivationReference.IsAllowed(this, __Context.Web);
            NWWorkflowContext ctx = NWWorkflowContext.GetContext(
               this.__Context,
               new Guid(this.__ListId),
               this.__ListItem.Id,
               this.WorkflowInstanceId,
               this);
            base.LogProgressStart(ctx);

            //Get the property value.
            string resolvedProperty = ctx.AddContextDataToString(this.Property);

            var result = "";

            //Using the context get the property if it exists.
            if (ctx.Web.AllProperties.ContainsKey(resolvedProperty))
            {
                result = ctx.Web.AllProperties[resolvedProperty].ToString();
            }
         
            //store the result.
            this.ResultOutput = result;
            //End Execution.
            base.LogProgressEnd(ctx, executionContext);
            return ActivityExecutionStatus.Closed;
        }

        protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext, Exception exception)
        {
            Nintex.Workflow.Diagnostics.ActivityErrorHandler.HandleFault(executionContext, exception,
                this.WorkflowInstanceId, "Error Reading from Property Bag", __ListItem.Id, __ListId, __Context);

            return base.HandleFault(executionContext, exception);
        }
    }
}

Read FromProperty Adapter
-----------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Workflow.ComponentModel;
using Microsoft.SharePoint;
using Nintex.Workflow;
using Nintex.Workflow.Activities.Adapters;

namespace CFSP.CustomActions.ReadFromPropertyBag
{
    public class ReadFromPropertyBagAdapter : GenericRenderingAction
    {

        private const string PropertyProperty = "Property";
        private const string ResultOutputProperty = "ResultOutput";

        public override NWActionConfig GetDefaultConfig(GetDefaultConfigContext context)
        {
            NWActionConfig config = new NWActionConfig(this);

            config.Parameters = new ActivityParameter[2];

            //define the parameters that the user can configure for this action.
            config.Parameters[0] = new ActivityParameter();
            config.Parameters[0].Name = PropertyProperty;
            config.Parameters[0].PrimitiveValue = new PrimitiveValue();
            config.Parameters[0].PrimitiveValue.Value = string.Empty;
            config.Parameters[0].PrimitiveValue.ValueType = SPFieldType.Text.ToString();

            config.Parameters[1] = new ActivityParameter();
            config.Parameters[1].Name = ResultOutputProperty;
            config.Parameters[1].Variable = new NWWorkflowVariable();

            //set the default label for the action.
            config.TLabel = ActivityReferenceCollection.FindByAdapter(this).Name;
            return config;

        }

        public override bool ValidateConfig(ActivityContext context)
        {
            //Add logic to validate the configuration here.
            bool isValid = true;

            Dictionary<string, ActivityParameterHelper> parameters = context.Configuration.GetParameterHelpers();

            if (!parameters[PropertyProperty].Validate(typeof(string), context))
            {
                isValid &= false;
                validationSummary.AddError("Property Bag", ValidationSummaryErrorType.CannotBeBlank);
            }
            return isValid;
        }

        public override CompositeActivity AddActivityToWorkflow(PublishContext context)
        {
            //Create an instance of the Activity and set its properties based on config. Add it to the parent activity
            Dictionary<string, ActivityParameterHelper> parameters = context.Config.GetParameterHelpers();

            ReadFromPropertyBagActivity activity = new ReadFromPropertyBagActivity();
            parameters[PropertyProperty].AssignTo(activity, ReadFromPropertyBagActivity.PropertyProperty, context);
            parameters[ResultOutputProperty].AssignTo(activity, ReadFromPropertyBagActivity.ResultOutputProperty, context);

            activity.SetBinding(ReadFromPropertyBagActivity.__ContextProperty, new ActivityBind(context.ParentWorkflow.Name, StandardWorkflowDataItems.__context));
            activity.SetBinding(ReadFromPropertyBagActivity.__ListItemProperty, new ActivityBind(context.ParentWorkflow.Name, StandardWorkflowDataItems.__item));
            activity.SetBinding(ReadFromPropertyBagActivity.__ListIdProperty, new ActivityBind(context.ParentWorkflow.Name, StandardWorkflowDataItems.__list));

            ActivityFlags f = new ActivityFlags();
            f.AddLabelsFromConfig(context);
            f.AssignTo(activity);

            context.ParentActivity.Activities.Add(activity);
            return null;
        }

        public override NWActionConfig GetConfig(RetrieveConfigContext context)
        {
            //Read the properties from the context.ACtivity and update the values in the NWActionConfig
            NWActionConfig config = this.GetDefaultConfig(context);

            Dictionary<string, ActivityParameterHelper> parameters = config.GetParameterHelpers();
            parameters[PropertyProperty].RetrieveValue(context.Activity, ReadFromPropertyBagActivity.PropertyProperty, context);
            parameters[ResultOutputProperty].RetrieveValue(context.Activity, ReadFromPropertyBagActivity.ResultOutputProperty, context);

            return config;
        }

        public override ActionSummary BuildSummary(ActivityContext context)
        {
            // Construct an ActionSummary class to display details about this action.
            Dictionary<string, ActivityParameterHelper> parameters = context.Configuration.GetParameterHelpers();
            return new ActionSummary("Retrieve the following Property bag: {0}", parameters[PropertyProperty].Value);
        }
    }
}




Comments

Popular posts from this blog

PowerShell For create Sub site in office 365

#Add references to SharePoint client assemblies and authenticate to Office 365 site Add-Type -Path "\Software\SharePoint 2013 Client Browser v1.7\Microsoft.SharePoint.Client.dll" Add-Type -Path "\Software\SharePoint 2013 Client Browser v1.7\Microsoft.SharePoint.Client.Runtime.dll" $Username = Read-Host -Prompt "Please enter your username" $Password = Read-Host -Prompt "Please enter your password" -AsSecureString $Site = "https://XXXXXXX.sharepoint.com/sites/Test2/" $Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site) $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password) $Context.Credentials = $Creds $csvLocation = "C:\Users\PS_SiteCollectionsToCreate.csv" $csv = Import-Csv $csvLocation #List Custom Templates $Templates = $Context.Site.GetWebTemplates("1033","0") $Context.Load($Templates) $Context.ExecuteQuery() $Templates | Whe...

SharePoint Capacity Management and Sizing Overview

Capacity management   is an ongoing process, because no implementation remains static with regard to content and usage. You need to plan for growth and change, so that your SharePoint Server 2013–based environment can continue to deliver an effective business solution. Capacity Planning  is only one part of the capacity management cycle. It is the initial set of activities that brings the design architect to the point where there is an initial architecture that the architect believes will best serve the SharePoint Server 2013 deployment. The capacity management model includes additional steps to help you validate and tune the initial architecture, and provides a feedback loop for re-planning and optimizing the production environment until it can support design goals with optimal choices of hardware, topology, and configuration. Capacity management versus capacity planning Capacity management extends the concept of capacity planning to express a cyclical appr...

Convert SharePoint Date in to ConvertDateToISO - And Use for Custom Save

-------------Code ------------------------------------------- function ConvertDateToISO(dtDate) { //************************************************* //Converts Javascript dtDate to ISO 8601 standard for compatibility with SharePoint lists //Inputs: dtDate = Javascript date format (optional) //************************************************* //alert("InISOCOnversion");   var d;   if (dtDate != null)  {      //Date value supplied           d = new Date(dtDate);   }   else  {      //No date supplied, Create new date object      d = new Date();   }   //Generate ISO 8601 date/time formatted string   var s = "";   //alert(d.getFullYear());    if(d.getFullYear)    {    //alert("FullYear");          s += d.getFullYear() + "-";     }     else     {      //alert("ge...