cancel
Showing results for 
Search instead for 
Did you mean: 
scheevel
Nintex Newbie

Value of common 'Current User' in JavaScript

Jump to solution

When I execute the following Custom JavaScript in Nintex Forms I get an unexpected result...

     NWF.FormFiller.Events.RegisterAfterReady( function() { console.log( 'Current User' ); } );

I would expect the result to be something like...
    i:0#.w|myDomain\myUserId
But instead I get back...
    i:0#.w|myDomainM77
What is "M77" and how can I translate this into an identifiable user value?  Thanks.

Labels: (2)
Tags (2)
0 Kudos
Reply
5 Replies
Automation Master
Automation Master

Re: Value of common 'Current User' in JavaScript

Jump to solution

likely backslash and first character from user account is interpreted as a special escaped character (eg \n => new line) by javascript

I'd suggest to let evaluate CurrentUser reference by a caclulated value control and then in javascript reference calculated value control. it should handle backslashes correctly.

View solution in original post

Reply
scheevel
Nintex Newbie

Re: Value of common 'Current User' in JavaScript

Jump to solution

That works - thanks! 

Reply
Automation Master
Automation Master

Re: Value of common 'Current User' in JavaScript

Jump to solution

great!

please mark the question answered.

0 Kudos
Reply
allan
Nintex Newbie

Re: Value of common 'Current User' in JavaScript

Jump to solution

@emha, unfortunately, this solution does not work everytime. Let me explain :
- If you put "Current User" in a calculated value (formula is "Current User" without the quotes)  and get the value via JS, it will work on loading. (getMyValue is in a file)

NWF.FormFiller.Events.RegisterAfterReady(function () {
    getMyValue(currentUserCalculatedControl);
});

- Press F5 to reload the form (which is different from loading the page from the URL bar of the browser, or clicking new item), you will have the following error :

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

The function "getMyValue " is not even triggered, it breaks before.
It breaks because the calculated control does not recalculate correctly on reload.
- Ctrl + F5 will work in any case
So this solution is a good start but not sufficient, do you have another idea to make it work ?

Thanks Smiley Wink

0 Kudos
Reply
allan
Nintex Newbie

Re: Value of common 'Current User' in JavaScript

Jump to solution

In fact, it is the function that does not work on reload with F5.
Specifically "getUserField.add(data[0]);" for some obscure reason that I have not found yet.

function getMyValue(currentUserCalc) {
    var currentUser = NWF$("#" + currentUserCalc).val();
    var getUserField = new NF.PeoplePickerApi('#' + peoplePickerPersonContact);
    getUserField.clear();
    getUserField.search(currentUser).done(function (data) {
        getUserField.add(data[0]);
    });
}

 

 

0 Kudos
Reply