current user in Manage Plumsail lookups

rss

Posted by RMIC - Jun 29 ’15 at 08:14

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 smile

  • RMIC
    Member
    Member for: 4 years 7 months 4 days
    #1 by RMIC Jun 30 ’15 at 04:57

    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.

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 8 days
    #2 by rostislav Jul 2 ’15 at 10:24

    [#1]:

    To get the user's id that is located in your lookup list:

    var str = fd.field('userLookupField').control()._el().find("a").attr('href');
    var res = str.match(/\?ID=([^&]+)/g);
    var id = res[0].substring(4);
    
  • RMIC
    Member
    Member for: 4 years 7 months 4 days
    #3 by RMIC Jul 3 ’15 at 05:59

    Unfortunately, the following error occurs:

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

    What could be the reason?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 6 years 2 months 25 days
    #4 by Dmitry Kozlov Jul 6 ’15 at 08:44

    [#3]: 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
    Member
    Member for: 4 years 7 months 4 days
    #5 by RMIC Jul 6 ’15 at 10:03

    [#4]: 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);

    }

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 7 months 8 days
    #6 by rostislav Jul 6 ’15 at 11:44

    [#5]:

    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 [email protected] and we'll check what the problem is.

Displaying 1 to 6 of 6 messages