current user in Manage Plumsail lookups
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.
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.
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);
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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.
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);
}
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);
}
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.
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.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 5 guests