Page 1 of 1

current user in Manage Plumsail lookups

Posted: 29 Jun 2015
by RMIC
Hello,

how do I get the current user set in the display form in a Manage Plumsail lookups?
In a field people it works without problems.

Thanks :)

Re: current user in Manage Plumsail lookups

Posted: 30 Jun 2015
by RMIC
Hi,

a few more detailed information.

The Plumsail lookup references another list with names.

In the Plumsail lookup are entered the current user, which is also contained in the other list.

I get the current name in the Plumsail lookup, but I still need the interene ID from the list of names.

Re: current user in Manage Plumsail lookups

Posted: 02 Jul 2015
by rostislav
To get the user's id that is located in your lookup list:

Code: Select all

var str = fd.field('userLookupField').control()._el().find("a").attr('href');
var res = str.match(/\?ID=([^&]+)/g);
var id = res[0].substring(4);

Re: current user in Manage Plumsail lookups

Posted: 03 Jul 2015
by RMIC
Unfortunately, the following error occurs:

The property "match" to undefined or zero reference can not be retrieved.

What could be the reason?

Re: current user in Manage Plumsail lookups

Posted: 06 Jul 2015
by Dmitry Kozlov
Did you insert the code into JS-editor of Forms Designer? Please, ensure that you specified the correct internal name of the lookup field in fd.field method.

Re: current user in Manage Plumsail lookups

Posted: 06 Jul 2015
by RMIC
Yes, the code is in JS editor and I have the internal name used.

If I let me output "str", is that "str" undefined.

My current complete code:


SetCurrentUserToField(_spPageContextInfo.userId, "Name");

//Function retrieves the current user name and bears in asynchronously in a form field

function SetCurrentUserToField(userid, fieldName) {

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";

var requestHeaders = { "accept" : "application/json;odata=verbose" };

$.ajax({

fieldname: fieldName,

url : requestUri,

contentType : "application/json;odata=verbose",

headers : requestHeaders,

success : onSuccessSetCurrentUserToField,

error : onErrorSetCurrentUserToField

});

}

//Callback for successful Ajax Cal

function onSuccessSetCurrentUserToField(data, request){

var loginName = data.d.Title;

SetUserFieldValue(this.fieldname,loginName);

}

//Callback for faulty Ajax Cal

function onErrorSetCurrentUserToField(error) {

alert(error);

}

//set the data

function SetUserFieldValue(fieldName, userName, userId) {


var str = fd.field(fieldName).control()._el().find("a").attr('href');

alert("str: "+str);

var res = str.match(/\?ID=([^&]+)/g);

alert("res: "+res);

var id = res[0].substring(4);

alert("id: "+id);



fd.field(fieldName).value({Id: id, Title: userName});

//fd.field(fieldName).readonly(true);

}

Re: current user in Manage Plumsail lookups

Posted: 06 Jul 2015
by rostislav
I can't reproduce your issue. I've copy-pasted your code and it works without any changes on my side. Are you sure "Name" is the corrent Internal Name of the field? Please note that internal name is not the same as title.

If my guess is wrong please send the html of your display page to support@spform.com and we'll check what the problem is.