Skip to main content

Hi every one,


Is it possible to set value to a hidden field in sharepoint list by K2 "Sharepoint List Items" Event. If not, is there any other way to make it.


Thank you for your help

We cannot update hidden fields directly from SharePoint list server event. In order to edit it, we need to set CanToggleHidden attribute to true & then we can unhide the field & can edit it using SharePoint Object Model.


 


We can use class library project with in K2 workflow and includes SharePoint object model functions to unhide the columns and update the unhide columns. Refer the library to K2 workflow project using references and by using K2 Default Server Event (Code) we can access the SharePoint Object Model methods.


 


Here is the code to unhide the list columns:


 


Add System.Reflection namespace.


 


  using (SPSite spSite = new SPSite(site url))


    {


    using (SPWeb spWeb = spSite.OpenWeb())


    {


    SPList spList = spWeb.Listsi"SharePointCustomList"];


    spWeb.AllowUnsafeUpdates = true;


    SPField listTitle = spList.Fieldss"Title"];


    Type type = listTitle.GetType();


    MethodInfo objMethodInfo = type.GetMethod("SetFieldBoolValue",BindingFlags.NonPublic | BindingFlags.Instance);


    objMethodInfo.Invoke(listTitle, new objectn] { "CanToggleHidden", true });


    listTitle.Hidden = false;


    objTitle.Update();                                  


    }


  }


 


Note: We can also achieve this using web methods.


Reply