Split UserName into Domain and User Id
Hi Guys,
I am using User Name from system data in my eform and it is giving Domain\UserId. Is there a way to split this into Domain and User Id as two different fields?
Any help would be appreciated..
Thanks,
Anil
-
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
-
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
}
}); -
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 -
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?
-
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);
}
}); -
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
}
});
} -
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");
-
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
-
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
Please sign in to leave a comment.
Comments
15 comments