Skip navigation
All Places > Getting Started > Blog > Authors christopheraucq

Getting Started

2 Posts authored by: christopheraucq Champion

Why this article?

Because the Related Item column is not yet available in the Nintex Form in O365.

 

This article is a follow-up to Delegation in O365

In my workflow, I really want to display the link to the document that needs approval in the task.
So, I decide to validate the Delegated action by checking if DelegatedTo is empty of not in the SharePoint Form.


In SharePoint 2013, the EditForm.aspx contains a Javascript validation function called PreSaveItem().
The trick here is to use this name to execute your own code. Note that the PreSaveItem() function of SharePoint will still run.

 

I need to validate only if the Content Type is Workflow Approve. But this field is not displayed if there is only one Content Type.

That is why I am also testing the empty value in the following line
if (strContentType == "Workflow Approve" || strContentType === '')

 

In my case, I have choosed to use the Person or Group column type.
In SharePoint, you cannot test a Person or Group column like a Single text column.
With the help of jQuery, I get an handle to the DelegatedTo field.
I make sure the name is resolved. If this is the case, I get the User object and get the Key property.

var ppDiv = $("[id$='ClientPeoplePicker'][title='" + strControlDelegatedTo + "']");

var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];

spPP.AddUnresolvedUserFromEditor(true);

var myUser = '';

if (!spPP.HasInputError) {

   var userKeys = spPP.GetAllUserInfo();

   myUser = userKeys[0];

}

if (myUser != undefined) {

   strDelegatedTo = myUser.Key;

}


If it is not empty, the field can pass the validation, otherwise, I display the validation message and I reset the Task Outcome value to avoid that the message is displayed if the user click Save afterwards.

 

Let's add some Javascript in the SharePoint EditForm.aspx. To accomplish that, open your Workflow Tasks list.

In The List Ribbon, click Form Web Parts - Default Edit Form.
Click Add a Web Part: Media and content - Script Editor and click Add.
Click Edit Snippet and paste this code:

 

<script language="javascript" type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
});
function PreSaveItem() {
    //Only for Workflow Approve Content Type
    var strContentType = $("select[title='Content Type'] option:selected").text();
    if (strContentType == "Workflow Approve" || strContentType === '') {
        var strTaskOutcome = $("select[title='Task Outcome'] option:selected").text();
        if (strTaskOutcome != "Delegated") {
            return true;
        }
        var strDelegatedTo = "";
        var strControlDelegatedTo = "DelegatedTo";
        var ppDiv = $("[id$='ClientPeoplePicker'][title='" + strControlDelegatedTo + "']");
        var spPP = SPClientPeoplePicker.SPClientPeoplePickerDict[ppDiv[0].id];
        spPP.AddUnresolvedUserFromEditor(true);
        var myUser = '';
        if (!spPP.HasInputError) {
            var userKeys = spPP.GetAllUserInfo();
            myUser = userKeys[0];
        }
        if (myUser != undefined) {
            strDelegatedTo = myUser.Key;
        }
        if (strDelegatedTo != "") {
            return true;
        } else {
            alert('Please select the delegated person.');
            $("input[title='DelegatedTo']").focus();
            $("select[title='Task Outcome']").val("");
            return false;
        }
        return false;
    }
    return true;
}
</script>

 

Hope this helps

Christophe Raucq

christopheraucq

Delegation in O365

Posted by christopheraucq Champion Feb 26, 2015

The action Assign Flexi Task is under development for O365.

Recently, the Task Outcome for Assign a Task was released.

The Delegation of a Task becomes then more intuitive.

Here is how I have implemented it.

 

1. Let's create a new Site column for the Task Outcome.

Go to Site Settings of your Site Collection and under Web Designer Galleries, click Site columns

Click Create and name it like you wish. I have name it Task Outcome Approve.

For The type of information, tick Task Outcome.

For Group, the best practice is to create a New group to store your customized columns. I have name it My Company.

For Type each choice on a separate line: add

Approved

Rejected

Delegated

Remove the Default value

Click OK

 

2. Add a new Site column DelegatedTo to the Workflow Approve content type.

In my case, I have create a column of type Person or Group but it can be a lookup column from a list containing the names of the Person

For Group, select the Group you justhave created.

Click OK

 

3. Create a new Site Content Type.

Go to Site Settings of your Site Collection and under Web Designer Galleries, click Site content types.

Click Create and name it like you wish. I have name it Worklow Approve.

For the Select parent content type from, select List Content Types.

For the Parent Content Type, select Workflow Task (SharePoint 2013)

For Group, create a New group to store your customized Content Type. I have name it My Company

Click OK

 

4. Add both Site columns to the Workflow Approve content type.

Click Add from existing site columns

Select columns from: Name of your customized group

In Available columns, select Task Outcome Approve and DelegatedTo and click Add.

Click OK.

 

Now, we need to customize the Workflow Task list but it does not exist yet.

So, let's create our Nintex Workflow.

In the Documents Library or any other Library/List you want, open the ribbon and click Nintex Workflow.

Do not add any action, just save it.

 

5. Add the new Content Type to the Workflow Tasks list used by your Nintex Workflow.

In the Quick launch, under Recent, click Workflow Tasks.

Go to the List Settings.

If you do not see the Content Types, click Advanced Settings. For Allow management of content types? Tick Yes

Click Add from existing site content types

From Select site content types from: select the new group you should have created. In my case, it is My Company

From Available Site Content Types, select Workflow Approve

Click Add and then OK.

 

Now, we need to make sure that there is only one content type displayed.

Click Change new button order and default content type

For the Task content type, uncheck Visible.

Click OK

And we need to make sure that the default Task Outcome is hidden.

Click you content type Workflow Approve.

Click Task Outcome

Tick Hidden

Click OK

 

6. Add the Assign a Task action

Open your newly created Nintex Workflow
Insert the Assign a Task action and click Configure.

Participant: Name of the assignee

Task Title, Description: What you want

Due Date: Left empty

Related Item: Keep Current item

Task Outcomes: Click Use existing predefined content type

Content Type: Select Workflow Approve

Field: Select Task Outcome Approve

For the remaining fields, you can let the defaults for this purpose

Click OK and you can see the three possible ouctomes for the Task.

 

31/03/2016 I have attached a js file with the code to validate the Delegated person.

To add this code, go to the Task list, click the List ribbon, Customize List group, Form Web Parts - Default Edit Form

Add a Web Part. Media and Content - Scripty Editor. Click Add.

Click Edit Snippet, paste the code and click Insert

 

Happy Nintexing,

Christophe Raucq

Filter Blog

By date: By tag: