Pages

Friday, June 27, 2014

Remove the Content Type drop down in SharePoint 2013 Workflow Task list

Introduction

So, Here is my second post on SharePoint 2013 workflow.

Problem Background

After creating a workflow task through custom content type, there is a dropdown showing the content types which were inherited from workflow tasks content type as in the screenshot below. I need to hide the drop down.

image

Solution 01

  1. Open the the Workflow Task list in browser
  2. Go to list settings and click on Advanced Settings
  3. There under “Content Types”, you have “Allow management of content types?” as radio buttons
  4. Select “No” option.

image

Solution 02

  1. Open the the Workflow Task list through SharePoint Designer 2013.
  2. Under setting panel there is a check box for “Allow management of content types”. Un tick that check box and save.

image

Conclusion

Now the user cannot see the dropdown for selecting content type.

image

Thursday, June 26, 2014

Create custom outcome options in workflow tasks for SharePoint 2013 workflow

Introduction

I was assigned to a project where I need to come up with workflow as a part of the module. For the first time I’m developing SharePoint workflows and I may get a chance to share some of the knowledge I will be gaining in upcoming days.

Problem Background

I had to assign a workflow task to a user and the task out come should be “Submit” and “Reject”. The default is usually “Approved” and “Rejected” as shown in the below screenshot.

image

The requirement is something like this.

image

Solution

  • You have to create a custom content type
    • Go to Site Settings –> Site content types –> Click Create
        • Fill Name and Description field
        • Select “List Content Types” under “Select parent content type from:”
        • Select “Workflow Task (SharePoint 2013)” "under “Parent Content Type:”
        • See the screen shot.

      image

        • Click OK
        • Once the page is redirected to the content type page ensure that the parent of the content type is Workflow Task (SharePoint 2013)

image

  • Add new site columns with the options we need for new task out come.
    • On the Site Content Type Page under Columns click “Add from new site column”
    • Give the Column Name as your wish
    • The type of information in this column is: should be “Task Outcome”
    • and you have to give the choices in “Type each choice on a separate line:” text area. I have given Submit and Reject.

    image

  • Remove the default task out come from the created content type
    • Click on Task Outcome under Columns section and click Remove.
  • Lets assign set the outcome option with the above create content type
    • Create a List workflow through SharePoint designer 2013
    • From the action menu add Assign a task action
    • Click this user and set the Participant and task title
    • Click Outcome options and select the content type created here the name of the content type is “Name” as we created above.

    image

  • Now we can get the output values from the workflow in the designer.

image

  • When we select the custom content type we will get an alert in read saying “Check to make sure this content type is applied to the workflow’s task list”
    • When we assign a task the task is created in a separate list. The default is Workflow task list. We can create as we want.
    • We can see the task list in workflow settings page

image

  • We have set the above created content type to the workflow task list.
    • Go to Workflow task list (Or your custom task list) through site content page
    • Then List Setting –> Under Content Types click “Add from existing site content types”
    • Add the content type we created.

image

    • Click OK.

That's all.

Conclusion

Now once we assign a task the task will have the above created outcome options in the tasks item. Don't miss the point associating the content type with the task list; else you will get a exception.

Monday, June 16, 2014

Work Item Timer Jobs - Presentation

Sri Lanka SharePoint Forum June 2014 offline meeting happened on June 11th. My tech lead Dinusha Kumarasiri did the first session on “How to use Provisioning Providers” and I did the second session on “Work Item Timer Jobs in SharePoint”.
This is my first ever session on SharePoint forum and also the first session on a public forum. I would like to thank Prabath Fonseka and Wellinton Perera for providing me with this opportunity, and also would like to extend my thank all the participants.
10393838_10152318026097530_3673986027299882108_n

 

Source Code

https://drive.google.com/file/d/0ByEnOE8DAdvhbkphQlpacWlySkU/edit?usp=sharing

 

Photos





Thursday, June 5, 2014

Add, Update and Delete SPListItem in SPList using JavaScript Object Model

Introduction

One person commented that - he needs to know How to Add, Update and Delete SPListItem in a SPList using JavaScript Object Model in a previous blog post. So I thought of writing a post for him; and which may useful for other new SharePoint newbies too.

Solution

Add

  1. function Add() {
  2.     var clientContext = new SP.ClientContext();
  3.     var oWeb = clientContext.get_web();
  4.     var oList = oWeb.get_lists().getByTitle('List1');//Get SPList by Title
  5.     var itemCreateInfo = new SP.ListItemCreationInformation();
  6.  
  7.     var oListItem = oList.addItem(itemCreateInfo);
  8.     oListItem.set_item('Title', 'Value'); //Title is the field and Value is the value for field
  9.     oListItem.update();
  10.  
  11.     clientContext.load(oListItem);
  12.     clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
  13.  
  14.     //Function when the execution of the query successed
  15.     function onQuerySucceeded(sender, args) {
  16.         alert('Data ADDED successfully');
  17.     };
  18.     //Function to run when the execution falis
  19.     function onQueryFailed(sender, args) {
  20.         alert('Cannot ADD');
  21.     };
  22.  
  23. };

Update

  1. function Update() {
  2.     var clientContext = new SP.ClientContext();
  3.     var oWeb = clientContext.get_web();
  4.     var oList = oWeb.get_lists().getByTitle('List1');//Get SPList by Title
  5.  
  6.     var oListItem = oList.getItemById(1);//Get the list item by id
  7.     oListItem.set_item('Title', 'New Value');
  8.     oListItem.update();
  9.     clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
  10.  
  11.     //Function when the execution of the query successed
  12.     function onQuerySucceeded(sender, args) {
  13.         alert('Data UPDATED successfully');
  14.     };
  15.     //Function to run when the execution falis
  16.     function onQueryFailed(sender, args) {
  17.         alert('Cannot UPDATE');
  18.     };
  19. };

Delete

  1. function Delete() {
  2.     var clientContext = new SP.ClientContext();
  3.     var oWeb = clientContext.get_web();
  4.     var oList = oWeb.get_lists().getByTitle('List1');//Get SPList by Title
  5.  
  6.     var oListItem = oList.getItemById(1);//Get the list item by id
  7.    oListItem.deleteObject();
  8.     clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
  9.  
  10.     //Function when the execution of the query successed
  11.     function onQuerySucceeded(sender, args) {
  12.         alert('Data DELETED successfully');
  13.     };
  14.     //Function to run when the execution falis
  15.     function onQueryFailed(sender, args) {
  16.         alert('Cannot DELETE');
  17.     };
  18. };

You can download the entire solution from the below url. https://drive.google.com/file/d/0ByEnOE8DAdvhSWFfM0Jja1FHMms/edit?usp=sharing