current user in Manage Plumsail lookups

Discussions about Cross-site Lookup
Locked
RMIC
Posts: 96
Joined: Sun May 10, 2015

29 Jun 2015

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 :)

RMIC
Posts: 96
Joined: Sun May 10, 2015

30 Jun 2015

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.

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

02 Jul 2015

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);

RMIC
Posts: 96
Joined: Sun May 10, 2015

03 Jul 2015

Unfortunately, the following error occurs:

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

What could be the reason?

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

06 Jul 2015

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.

RMIC
Posts: 96
Joined: Sun May 10, 2015

06 Jul 2015

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);

}

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

06 Jul 2015

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.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 5 guests