Split UserName into Domain and User Id

Comments

15 comments

  • Avatar
    Alexey Shmelkin (sysberry-absc.com)

    Hi Anil,

     

    you can get the variable in JS with this: 

    https://documentation.agilepoint.com/00/appbuilder/cloudjsGetFieldValue.html

    then modify it 

    var Domain = result.data.split("\\")[]; //get Domain

    var UserId = result.data.split("\\")[1]; //get UserId

    and then put to the control you want with this:

    https://documentation.agilepoint.com/00/appbuilder/cloudjsSetFieldValue.html

    Feel free to ask further questions!

    Regards,

    Alexey

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Thanks Alexey,

    I used below JS code to log the field value into the console but it seems didn't worked. It's logging empty data object. Please let me know if I am missing anything in here.

    var options = {};
    options.fieldId = 'UserName'; // individual control
    eFormHelper.getFieldValue (options, function (result)
    {
    if (result.isSuccess) //check if is success
    {
    console.log(result.data); //logs the data holds the found control's value
    }
    else
    {
    console.log(result.error); //logs the error
    }
    });

    0
    Comment actions Permalink
  • Avatar
    Alexey Shmelkin (sysberry-absc.com)

    Can you look, what is it in the result (not only in result.data) with console? What is the internal name of the control, where UserName was saved? Screenshots would help.

    Regards,

    Alexey

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Hi Alexey,

    UserName is an internal name of the form control. If you see in the console screenshot the object has empty data value.

     

    0
    Comment actions Permalink
  • Avatar
    Alexey Shmelkin (sysberry-absc.com)

    Hi Anil,

    I guess you are trying to do this on form preview. There ${UserName} won't be resolved. Publish it and start the workflow - then it will work. For test purposes in Form Breview you can just put "abc\cde" as default value. After you are done with testing - use $ and test it in running mode and not in preview.

    Regards,
    Alexey

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Thanks Alexey for helping me out..

    As you said, for the preview purpose I entered sample text (Domain\UserId) in the default value section as below screenshot but still see blank in data property. I even tried publishing the form but still see the same.

    0
    Comment actions Permalink
  • Avatar
    Paul Horvath

    to help you debug, I recommend adding the javascript to be triggered when that field changes.

     

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Hey Paul Horvath,

    Can you please send me the java script code for that??

    0
    Comment actions Permalink
  • Avatar
    Paul Horvath

    in the UserName textbox, on the Advanced tab, in the JavaScript event select CHANGE. In the JavaScript function select your javascript function via the dropdown.  once in place, you can use the PC Browser instead of always having to publish/test.

    Can you post your current Javascript?

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Thanks Paul Horvath,

    Below sample JS code is being used in the form. Actually my requirement is to split Username (domain\userid) - currently logged in user into domain and User ID fields. I think we need to have on page load action to pre-populate these fields but I don't see such event in the drop down.

    var options = {};
    options.fieldId = 'UserName';
    eFormHelper.getFieldValue (options, function (result)
    {
    if (result.isSuccess)
    {
    console.log(result);
    }
    else
    {
    console.log(result.error);
    }
    });

    0
    Comment actions Permalink
  • Avatar
    Paul Horvath

    That doesn't appear to be proper JS structure, there should be a function declaration somewhere... (i am doing something similar for a folder parse)

    function fetchValue(fID)
    {
    var retval;
    retval = new String("null");
    var options = {};
    options.fieldId = fID; // individual control
    eFormHelper.getFieldValue (options, function (result)
    {
    if (result.isSuccess) //check if is success
    {
    console.log(result.data);
    retval = new String(result.data);
    //logs the data holds the found control's value
    }
    else
    {
    console.log(result.error); //logs the error
    retval = new String("error");
    }
    });
    return retval;
    }

    function SetCalcFolder()
    {
    debugger;
    // get DocLibPath
    var DocLibPath
    DocLibPath = new String("");
    DocLibPath = fetchValue("TextBox9");

    var Front = DocLibPath.split("/")[0];
    var Folder = DocLibPath.split("/")[1];
    setValue("CalcFolder",Folder);
    }

    function setValue(fID,thisValue)
    {
    var options = {};
    options.fieldId = fID; // individual control
    options.value = thisValue;

    eFormHelper.setFieldValue(options, function (result)
    {
    if (result.isSuccess) //check if is success
    {
    console.log(result.data); //logs the data holds empty object
    }
    else
    {
    console.log(result.error); //logs the error
    }
    });
    }

     

     

    0
    Comment actions Permalink
  • Avatar
    B Anilreddy

    Hi Paul Horvath,

    I tried below JS code but still didn't work. I even put this function in on change event also in the advanced tab of form control. Still it is giving empty data object. Here I created new text box which is TextBox18. I even tried your code as it is till DocLibPath = fetchValue("TextBox9");  just replacing field id from TextBox9 to TextBox18.

    Can you please tell me what I am missing in here. I just want to log the TextBox18 default value into the console here..

    function fetchValue(fID){
    var options = {};
    options.fieldId = fID;
    eFormHelper.getFieldValue (options, function (result){
    if (result.isSuccess){
    console.log(result);
    }
    else{
    console.log(result);
    }
    });
    }

    var fieldVal = fetchValue("TextBox18");

    0
    Comment actions Permalink
  • Avatar
    Alexey Shmelkin (sysberry-absc.com)

    Hi Anil,

    i have created a form with 2 controls:

    and a click button:

    with following JS:


    function splitUserName()
    {
    var options = {};
    options.fieldId="UserName1";
    eFormHelper.getFieldValue(options, function(result){
    console.log(result);
    var Domain = result.data.split("\\")[0]; //get Domain
    var UserId = result.data.split("\\")[1]; //get UserId
    console.log(Domain);
    console.log(UserId);
    });
    }

    After clicking on the button i see on console:

    can you try this out?

    Regards,

    Alexey

    0
    Comment actions Permalink
  • Avatar
    Anilreddy Bobbala

    Thanks Alexey, Its working now with the click event but my requirement is to pre-populate domain and UserId fields on form load based on the logged in user info.

    Is there any such kind of events we can put in here?

    0
    Comment actions Permalink
  • Avatar
    Alexey Shmelkin (sysberry-absc.com)

    On form builder you have a rule builder, where you can define rules on form load. There you have execute method, where you can choose this JS function. Alternatively you can also set the rule on any control and set the checkbox on the right bottom corner of rule builder "execute on form load also". Another method is with pure JS: https://documentation.agilepoint.com/00/appbuilder/cloudformEvents.html

    Regards,
    Alexey

    0
    Comment actions Permalink

Please sign in to leave a comment.