Skip navigation
All Places > Getting Started > Blog > 2018 > October
2018

I Recently had a request to get a Project Manager name that is linked to a project when the user selects a project number from a drop-down control.

 

I managed to get the Project managers name using this formula : lookup("Project List", "Project_x0020_Number", parseLookup(Project), "Project_x0020_Manager"). The only issue was I was also getting the ID along with the name. e.g.  234;#Joe Soap.

 

So, to fix this I used a regular expression to remove the ID from the front of the Project Managers name.

 

Steps I took:

1. I created a Form Variable. The formula I used to get the project managers name is : lookup("Project List", "Project_x0020_Number", parseLookup(Project), "Project_x0020_Manager")

 

"Project List" - is the name of the list that has the project number and project managers name in it.

"Project_x0020_Number"  - is the Project number for the Project. 

"Project" is the name of my drop down control that displays the list of Project numbers in it.

"Project_x0020_Manager" - is the name of the column in the "Project List" list that has the Project managers names in it.

 

 

2. I added a Calculated Value control to my Form. I used the regular expression in the formula to remove the characters before the #. 

This is the formula : replace(GetPMName, ".*#", "")

 

"GetPMName" - is the name of the form variable I created that holds the Project manager name with the ID attached to the front. e.g. 234;#Joe Soap.

".*#", ""  - is the expression I used. It removes everything before the # and replaces it with a empty string.

 

 

End result : Joe Soap.

 

Hope this helps someone. 

Interested in free Nintex training? Check out our latest intro course made for complete beginners to Nintex. Even if you've never heard of a workflow or automation, you can dive right into this course to gain a fundamental understanding of the Nintex Platform.

 

By learning the basics of lists, forms, and workflows, you can build a foundation on which to progress your skills through additional courses or other resources. Easy to follow videos and instructions will guide you every step of the way.

 

Visit https://learn.nintex.com/wp01-intro-to-nintex  to enroll in this course today. Happy learning, everyone! 

 

 

 

graham

Counting Records

Posted by graham Oct 12, 2018

I wanted to be able to do a Group Count on a set of items in a library (I actually wanted to save the values and counts to a list so that I could attach a chart control – but that’s another story).

There is no way of doing a Group By in the Query List task, so I had to come up with this.

Retrieve all my key values into a collection, then create a list of those unique key values

Iterate through the unique values and remove them from the original list – the number of items matching the key value is the number of items removed from the collection – the difference between the counts before and after the deletion.

In pseudocode, the process is this

QueryList : get all ‘key values’ in range into collection AllKeys

Collection: Remove duplicates from AllKeys into collection UniqueKeys

ForEach string Key in UniqueKeys

Collection: Count AllKeys into number Total

Collection: Remove by value Key from AllKeys

Collection: Count AllKeys into number Count

Math: Total Count into number KeyCount

{do something with Key and KeyCount}

EndLoop

There are many requirements where Approvers need to upload attachments on task form, which need to be uploaded on main item instead of task form.

I have achieved it using REST and JS.

 

Major Steps :

1. Create RichText Control on Text Form to show attachment and add attachment button.

2. Add JS which use REST API to add attachments

 

Requirement Result Screen :

 

On click of Show Attachment button, it loads attachments of Related item with add attachment link as shown below

on Add attachment it opens below screen and we can upload attachment by selecting file.

 

Solution

1. Drag a Task on workflow. Click on Edit Task form.

2. Add a Rich Text Control on form as shown in below screen

3. Edit Properties of Rich Text add below HTML in Rich text as shown below 

<input id="btnAttach" ="return checkSPLoad('');" style="width:180px;" type="button" value="Show Attachments" />

<div id="divAttachs"></div>

<div id="addAttachmentDiv" style="display:none;">Select a file<br />
      <strong>Name </strong>

      <input class="attachmentButton" id="attachmentButton" multiple="multiple" name="attachmentButton" ="attachFile(this);" type="file" />

</div>

<div class="nf-attachmentsLink" id="idAttachmentsLink" ="showAttch();" style="height:17px;display:none;">

      <img  />

        <a class="ms-addnew" href="#">Add Attachment</a>

</div>

 

4. Click On Save.

5. Select Form Setting in ribbon and add javascript.

6. Paste below script in custom javascript section.

var pollSP;  var hostweburl='';
var appweburl='';
var listname='ListName';//Include list name 
var itemid=ID;  //Include reference of ID of item.

var file;
var contents;
var itmUrl='';  
function checkSPLoad(callType){
 NWF$('#btnAttach').hide();
    if (clientContext){ 
        window.clearInterval(pollSP); 
        hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
        appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl")); 
        var layoutsPath = "/_layouts/15/"; 
        var scriptbase = appweburl + layoutsPath; 
        itmUrl=hostweburl+"/Lists/"+listname+"/Attachments/"+itemid;
        if(callType=='Post')
        {
               NWF$.getScript(scriptbase + "SP.js", function () {
                            NWF$.getScript(scriptbase+ "SP.RequestExecutor.js", execCrossDomainRequest);
               });
        }   
      else
        {
                  NWF$.getScript(scriptbase + "SP.js",   function () {
                            NWF$.getScript(scriptbase+ "SP.RequestExecutor.js", execCrossDomainGetRequest);
               });
        }
    } 
 
    function execCrossDomainRequest() {  
        var contents2 = _arrayBufferToBase64(contents);
        var executor = new SP.RequestExecutor(appweburl);             
        var digest =     NWF$("#__REQUESTDIGEST").val();  
        executor.executeAsync(  
          {         
            url:appweburl +   
            "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('"+listname+"')/items("+itemid+")/AttachmentFiles/add(FileName='"+file.name                   +"')?               @target='" +      hostweburl + "'",   
            method: "POST",   
            body: contents2 ,  
            binaryStringRequestBody: true,
            contentType: "application/json;odata=verbose",         
            headers: {            "X-RequestDigest": digest, "Accept": "application/json; odata=verbose"},                      
            success: function (data) {  
                   NWF$('#addAttachmentDiv').hide();
                   NWF$('#attachmentButton').val('');
                   execCrossDomainGetRequest();    NWF$('#idAttachmentsLink').show();
            },  
            error: function (err) {  
                var data=JSON.parse(err.body);
                ;
                   NWF$('#idAttachmentsLink').show(); 
                         NWF$('#addAttachmentDiv').hide();
                            NWF$('#attachmentButton').val('');    
            }   
        });                             
    }
   
 function execCrossDomainGetRequest() {  
       var executor = new SP.RequestExecutor(appweburl);             
        NWF$('#divAttachs').html("Loading...");
        executor.executeAsync(  
            {         
             url:     appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('"+listname+"')/items("+itemid+")/AttachmentFiles?@target='" +   
                         hostweburl + "'",   
             method: "GET",   
             headers: { "Accept": "application/json; odata=verbose" },                   
                success: function (data) { 
                    parseAttachment(data);
                             NWF$('#idAttachmentsLink').show();
                },  
   error: function (err) {  
    var data=JSON.parse(err.body);
     ; NWF$('#btnAttach').show(); 
    }   
   });                             
 }
}
function getQueryStringParameter(paramToRetrieve) {   
    var params =   
        document.URL.split("?")[1].split("&");     
    for (var i = 0; i < params.length; i = i + 1) {   
        var singleParam = params[i].split("=");   
        if (singleParam[0] == paramToRetrieve)   
            return singleParam[1];   
    }   
}
function showAttch()
{
 NWF$('#addAttachmentDiv').show();
 NWF$('#idAttachmentsLink').hide();

function parseAttachment(vdata)
{
 var html='';
 var data=JSON.parse(vdata.body);
 var items=data.d.results;
 for(i=0;i<items.length;i++)
 {
  html+='<a href="'+itmUrl+'//'+items[i].FileName+'" target="_blank">'+items[i].FileName+'</a><br>';
 }
 NWF$('#divAttachs').html(html);
}
function f"font-size: 12px;">    contents = event.target.result;
    checkSPLoad('Post');;
}
function attachFile(event) {
    var i = 0,
    files = event.files,
    len = files.length;
 if (files.length > 0) {
        file = files[0];
        fileName = file.name;
        var reader = new window.FileReader();
        reader. f"font-size: 12px;">        reader. = function(event) {
            console.error("File reading error " + event.target.error.code);
        };
        reader.readAsArrayBuffer(file);
    }      
    return false;
}
function _arrayBufferToBase64(buffer) {
    var binary = '';
    var bytes = new window.Uint8Array(buffer);
    var len = bytes.byteLength;
    for (var i = 0; i < len; i++) {
        binary += String.fromCharCode(bytes[i]);
    }
    return binary;
}


 Note : Update list name and id(Add reference from Item section) in top of script.

7. Save and close form.

 

Publish workflow and test.

 

Happy Nintexing.

Hello Everybody,

 

In calculated field have formula "userProfileLookup(Current User,"PreferredName")" is it possible to somehow transfer this information to field Single Line Textbox.

I already try to set this same connected field also make this solution Can't populate text control with calculated value 

but it doesn't collect any data to this field.

Is it some different solution for this ?

Filter Blog

By date: By tag: