[Nintex Workflow] Add user to Site Collection Administrator group with REST API

Standard

Helping people to automate their workplace is my passion and lucky for me I also get paid to do so !

This week I was finishing working with a partner to improve the (poor) automation steps required by Matter Center, which no-one can really complain because Microsoft made it open-source.
Matter Center documentation requires to create each client as a new site collection in PowerShell, but this is not quite possible if the users registering these new clients on a daily basis are regular Office 365 users and not SharePoint Administrators.Thanks to a few Nintex Workflows we managed to do all the configuration in the background.

Thanks to a few Nintex Workflows we managed to do all the configuration in the background.
Today’s post is not about the site collection creation so I will spare the details, but in summary and very high level, I developed 4 workflows, 1 CSOM Javascript to be executed on the browser, and 1 Nintex Form of course for submitting the new client on desktop or mobile.

Now this quick blog post is regarding the challenge that we had to add the user as a Site Collection Administrator of that newly created site collection.

Since there is no mention of the sort in https://community.nintex.com it may useful for someone, so here it is:

  1. Create a new Nintex workflow in an Office 365 site list.
  2. Download and Import the .NWP workflow file available here to replace the blank workflow
  3. Edit a few of the actions at the beginning of the workflow to set the variables (I never hard-code UserName and Password for instance, so you will see a few Lookup to a different list to get the value, which you can replace since they will be showing an error once imported into your list)

Note: In this workflow, the “user” I am adding to the Site Collection Administrators group is actually the “CreatedBy” of the list item, which may sound strange since the user running that workflow may be the CreatedBy. However this is NOT the case (refer to above point: we do not want all users to be SharePoint admins!), here is how you should sequence the workflow to start:
1) After the List Item is created, a first workflow (run by CreatedBy) i.e. called “Start and Call workflow 2” and in the workflow we just add a “Start Workflow”

2) then within that first workflow we just add a “Start Workflow” making sure that this action is bein executed in an “App Step” in order to use “elevated privilege”.

Nintex_Workflow_for_Office_365

3) finally all the actions are happening in Workflow2 (which you imported in step 2)

 

Hope this helps someone.

François.

Advertisements

August Nintex Workflow updates are very exciting.

Standard

So nice to be on Office 365 and not having a weekend downtime to upgrade a third party tool.

(read my comments on each item below)

We’ve made some changes since last time…

  • WorkflowGalleryWorkflow Gallery

    • Complete the work faster and with fewer clicks. When opening Nintex for Office 365, you’ll now see an entry page instead of the design canvas. From this entry page, you can create new workflows, modify existing workflows and delete unwanted workflows. Depending where you are in a workflow design when you open Nintex, it will display the relevant actions for that context first and then a secondary set for other workflows. Read more…

[FS] Opening an existing workflow was a bit puzzling vs. on premises Nintex because it would always open blank until we open it manually as if opening a previous version. Now it doesn’t feel like we have lost them, they are visible.

  • TaskEscalationTask Escalation

    • We’ve now introduced the option of escalating a task to someone else or completing a task after a set period of time. Find this capability within the Assign a Task and Start a Task Process actions. Read more…

[FS] This is excellent. We already had it on premises for a long time, now on Office 365.

This means that we can build something like: if a task is still awaiting a Manager who has not completed it within 5 days then Nintex Workflow will escalate automatically to another person to approve such as the manager of that last task assignee. Real business value !

Nintex Forms and Validation rules: a good feature added, but not so great yet for validating fields, Javascript to the rescue !

Standard

Nintex introduced validation rules in version v1.5.2.0 of Nintex Forms 2010 and v2.3.1.0 of Nintex Forms 2013. They provide a quick way for checking if a field has to be mandatory depending on a rule, hence make use of the Nintex Formula language to perform a logic that may be more advanced than just the “mandatory” default option in any SharePoint column.

However I found that the Validation Rules did not really help. The first inconvenience is that each field needs to have its rule and therefore if 20 fields: 20 rules to edit. Another problem I faced is that I wanted to compare Dates, or compare entered username with another. For some it is easier to just call for JavaScript function to evaluate my own rules.

I am therefore listing below what I have used as steps to add JavaScript validation to my Nintex Forms since I did find a few leads on Nintex Connect / Community site (mainly Vadim’s blog and these articles) but not one unique article to tackle all fields validation type.

Step 1:Give a JavaScript object name to each field that needs its value check

JS_Name

Step 2: Point the Nintex Forms Settings to use a custom JS file

Nintex_Form_Settings

Step 3: Tell the Submit button to use your JS function

Edit the Save & Submit button properties to call your Function CheckAllFields() when it is clicked

if(CheckAllFields() == true) {return true;} else {return false;}

Submit_button

 Note: Although some posts mentioned to switch the Button Type to “Javascript” in my case it would execute the code but not stop if validation failed (return false; was ignored) however leaving Type as “Button” did work. (may be a bug in Nintex Forms, as version experienced was Sept. 2014)

Step 4: Create a new text file on your site and paste the JavaScript code

Use a text editor or SharePoint Designer and save the following code in the same URL as defined in Step 2 (in my case

Site URL/Assets/scripts/FormFieldValidation.js)

function CheckAllFields()
{
     var tError=false;
     var thisField;
     var thisFieldName;
     // validate DROP DOWN list value
     thisField=jsDROPDOWN1;
     var thisFieldName = "Drop Down field"
     var myValue = NWF$("#" + thisField ).find(":selected").text();
     tError = CheckListField(myValue, thisFieldName);
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate RADIO BUTTON value
     thisField=jsRADIOBUTTON1;
     var thisFieldName = "Radio Button "
     var myValue = NWF$(NWF$("#" + thisField).find("input:checked")).val()
     tError = CheckRadioField(myValue, thisFieldName;
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate PEOPLE PICKER value
     thisField=jsPEOPLEPICKER1;
     var thisFieldName = "Person field"
     var myTextControl = NWF$("#" + thisField );
     var myValue = myTextControl.val();
     tError = CheckPeopleField(myValue, thisFieldName);
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate DATE value
     thisField=jsDATE1;
     var thisFieldName = "Date field"
     var myTextControl = NWF$("#" + thisField );
     var myValue = myTextControl.val();
     tError = CheckDateField(myValue, thisFieldName);
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate TEXT field value
     thisField=jsTEXT1;
     var thisFieldName = "Title Text field"
     var myTextControl = NWF$("#" + thisField );
     var myValue = myTextControl.val();
     tError = CheckTextField(myValue, thisFieldName);
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate MUTI LINE field value
     thisField=jsDescription;
     var thisFieldName = "Multi Line Description field"
     var myTextControl = NWF$("#" + thisField );
     var myValue = myTextControl.val();
     tError = CheckTextField(myValue, thisFieldName); // multi line field but Text only so can be compared just like Text field
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // validate CHECK BUTTON value
     thisField=jsDirectorates;
     var thisFieldName = "Check Radio button "
     var myValue = NWF$(NWF$("#" + thisField).find("input:checked")).val()
     tError = CheckRadioField(myValue, thisFieldName);
     if (tError==true) { NWF$("#" + thisField ).focus(); return false; } //if field is error: stop submission.

     // After all validation have passed let"s submit the form
     document.aspnetForm.submit();
     return true;
}

//
// FOR EACH TYPE OF FIELD WE MAY HAVE A DIFFERENT WAY OF CHECKING THE VALUE IS ENTERED OR SELECTED
// DEPENDING IF RADIO BUTTON, DATE (MAY HAVE TO COMPARE IT) ETC...
//
function CheckTextField(myValue, myLabel)
{
     if (myValue=="") // Text type field value can be compared with blank string
     {
          alert(myLabel + " cannot blank " );
          return true;
     }
     else
     {
          return false;
     }
} //end if value is not blank 

function CheckDateField(myValue, myLabel)
{
     if (myValue=="") // Date type field value can be compared with blank string
     {
          alert(myLabel + " cannot be blank");
          return true;
     }
     else
     {
     //convert value to date
     var myDate=myValue;
     myDate=myDate.split("/");
     var newDate=myDate[1]+"/"+myDate[0]+"/"+myDate[2];
     var inputDate = new Date(newDate); // convert the field value into Date
     var todaysDate = new Date(); // get Today"s date
     todaysDate.setHours(0,0,0,0); // reset the time of today to be able to compare if Today
     if(inputDate >= todaysDate) // compare Field date to Today date
     {
          alert(myLabel + " cannot be later than today");
          return true;
     }
     else
     {
          return false;
     }
     } //end if value is not blank
}

function CheckPeopleField(myValue, myLabel)
{
     if (myValue=="") // People field type value can be compared with blank string
     {
          alert(myLabel + " cannot blank");
          return true;
     }
     else
     {
          return false;
     }
} //end if value is not blank

function CheckListField(myValue, myLabel)
{
     if( myValue.indexOf("Please") >= 0 ) // Drop Down list position of the selected choice can be retrieved and make sure it is not the default choice which contains "Please select a choice in the list".
     {
          alert("Please select a " + myLabel );
          return true;
     }
     else
     {
          return false;
     }
} //end if value is not blank

function CheckRadioField(myValue, myLabel)
{
     if (myValue== undefined ) // Radio button are "undefined" if not selected
     {
          alert("Please select a " + myLabel );
          return true;
     }
     else
     {
          return false;
     }
} //end if value is not blank

Hope this help anyone who needs more control in the fields validation, this code is not perfect and has room to improve but I know it will help me next time.

Nintex Form doesn’t like you to make mistake

Standard

I have experienced this a few times developing a Nintex Forms when previewing a form I have just designed:

Nintex Form blank

and I always ended up to delete some rules, re-create them, re-check all of them just to find which of my fields’ rule was not hidden by itself but would hide the whole form.

I just managed to repeat the issue several times and it just lays with a missing parenthesis in a rule formula (!)

missing character in Nintex Form rule formula 

Obvious but when you have dozen of fields and rules, it would be nice that Nintex Forms preview doesn’t load and simply returns an “error” rather than just a blank form, right ?

 

Be careful using reserved word in Nintex formulas

Standard

As I was creating a simple form for my client I created a control in Nintex Forms called “TRIM” standing for “HP TRIM” and I just need to make another hidden control appear when the tick box is selected, just as illustrated below:

trim

To my surprise he didn’t work whatever I tested.

The rule formula to hide the controls were : 

– hide when this is true:  Not(TRIM)

After a while I realised that Nintex also provide a Runtime Function called “trim”Nintex Trim runtime function

So renaming the check-box control to “TrimService” (no change to the connected SharePoint field) fixed it, and here is the correct Rule Formula below, so be careful that Nintex doesn’t have its own reserved words.

Nintex Rule formula NoReserved word

Nintex workflow task not opening for some users

Standard

 

Small issue:
  Today I had an issue with some workflow task items, created by a Nintex Workflow which suddenly could not be opened by end users (by assignees that is): error below.Image

It was working for me and since I have higher permission on the site, after scratching my head a bit, I looked at the item permission : it was fine.
The issue laid with the actual “RelatedContent” item, ie. the item on which the workflow ran when it created the workflow task, the permission for this item were reduced to only the Author of the item and his/her manager, and it was missing some groups like Viewers.

Fix:
Adding the group to item level permission of the RelatedTo item fixed the issue and users could access the task again.

Root cause:

  • – some SharePoint groups have been renamed and the workflow which assigned the permission was trying to add the old names, resulting in none being added. The workflow permission action had to be re-done.
  • – although the workflow task item should be independent from the source item it is not because the Workflow task item also has an embedded webpart that is -sometimes- used to display columns from the RelatedContent item, therefore if that values cannot be read the whole task item errors.

Conclusion:

– be careful when renaming SharePoint group
– an item error may not be linked to the item itself

How create format HTML emails in Nintex Workflow actions

Standard

I will not repeat enough, when it comes to workflow design Nintex workflow is brilliant and save a lots of hassle.

lThis said not everything in this tool is that easy to achieve, today I am going to mention a basic workflow action that everyone will use for sure in any workflow: the “Send notification” action”

 

This action allows you to send an e-mail, a Lync message or even SMS to a user to inform them in the middle of a workflow.

The problem

“Send notification” comes with its own Rich Text editor to format the text and add reference of an item into the subject and body of the message. But very quickly you should realise that the editor has some limitations. In my experience I found it a bit buggy;  for instance : type some text, format it in blue, add field reference to se the values, then save the action and come back to the editor only to find that the 1 carriage return has expanded to 10 and the font you thought was the same in the whole email has change to another in the middle of the body content.

I actually believe that this is not really the problem with the editor itself but just a standard HTML issue: if you check the source of that rich text editor, you will see some characters and font styling that have been added which makes debugging quite hard.

How I do it

Ok, so this is my tip for dealing with HTML email:

1-     Forget about the Rich text editor

2-      Prepare your HTML body away from the workflow action

3-      When ready, paste it into the editor

 

Show me

Here is, in pictures, how I now do my email body content. My method may not be the best one and took a bit of time for the initial setup of the first email body, but the next ones can just be derived from it and then speed up the tasks. Also you will see that every time  you are requested to change a character in an email, it’s a “piece of cake”.

1-      Open NotePad (or already into an HTML editor such as a SharePoint Designer HTML file, myself I prefer to use NotePad++ as it formats HTML best)

2-      Start your email body with the labels and values you intend to display, leave the reference as a placeholder for now

3-      Capture the item values or variables that you need to need to show

In the Nintex “send notification” editor, remove all your Rich Text content and only add the single reference that you need, for instance if I want to display the “Title” field value:

4-      Copy the HTML of that reference

5-      paste it into the HTML file

6-      Start formatting some HTML around the item value

7- repeat step 3 to 6 until your HTML is complete
8- paste the HTML into the HTML editor of the Nintex Rich Text editor to obtain an email looking as:
9- Make sure you SAVE your HTML code into a file for re-usability.
Conclusion
Each time you need to edit a comma on your rich text email you do so in the HTML and paste it again in the editor. This way you won’t have strange behaviour in the editor.
Again: this is my method and may not be everyone’s choice, but since I had a workflow with around 6 different email templates this way was the only way I found to make sure that each email is similar except for a couple of fields, otherwise using the Rich Text editor in the Workflow Action (notification or Flexi-Task) didn’t prove to be formatted the same as another one.