Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2018-12-20 03:22 PM
Has anyone used a custom object to get current user name and update it in a text field.
I am working in Advanced Workflow and trying to get the name of the user who click the Approve button so that I can reflect it in a text field called Approver.
2019-01-18 12:54 PM
I was able to test the code today to populate a User/Group field and it worked perfectly fine in version 6.4.
Attaching the code below.
Question: How does your script appears in code format with line numbers. I couldn't find any option on the screen for it.
<img src="../BackgroundImageGenerator.axd?className=StyledButton&classProperties=caption:Add User;iconSetStyle:VistaRound;baseColor:%23DDDDDD;disabled:False" onclick="setRecordPermission()">
<script type="text/javascript">
var setUser = {
fldId: '35407',
usersName: parent.parent.ArcherApp.globals.displayName,
usersId: parent.parent.ArcherApp.globals.userId,
itemType: 'user'}; // Use 'group' if you're adding a group
function setRecordPermission() {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(setUser.fldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
UsrArray.push({
name: setUser.usersName,
value: setUser.usersId + ':' + (setUser.itemType == 'group' ? 3 : 1)
});
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="'+ RPFieldRootId +'_"] div:first-child').text(setUser.usersName);
$('input[id*="'+ RPFieldRootId +'_"]').val(serialized);
if(setUser.itemType == 'user'){
$('#SelectedUsers'+setUser.fldId).val(setUser.usersId);
}else if(setUser.itemType == 'group') {
$('#SelectedGroups'+setUser.fldId).val(setUser.usersId);
}
}
</script>
2018-12-20 03:33 PM
Use Global variables:
ArcherApp.globals.firstName
ArcherApp.globals.lastName
You should use it in Custom Object as:
parent.parent.ArcherApp.globals.firstName;
2019-01-08 12:22 PM
Thank you for the reply. I was able to capture the user name.However, I more question if you can help out. Is there a way I can capture this name in a text field or may be populate a user/group field with the logged in user name information?
2019-01-08 12:24 PM
2019-01-08 12:34 PM
You'll need to include the user id as well in order to populate the users/groups field.
For 6.4 or lower:
var userName = parent.parent.ArcherApp.globals.workpointFeature.UserName;
var userID = parent.parent.ArcherApp.globals.workpointFeature.UserId;
For 6.4 SP1+ use:
var userName = JSON.parse(JSON.parse(parent.parent.ArcherApp.globals.workpointFeature)).UserName;
var userID = JSON.parse(JSON.parse(parent.parent.ArcherApp.globals.workpointFeature)).UserId;
Advisory Consultant
2019-01-14 02:55 PM
Hi IIya
Got another question, I was looking at the responses on the post "Custom Object to Set User/Group Popup Field"
https://community.rsa.com/thread/77420
How do you get the FieldID. In Archer I see the Field ID is Alpha numeric for the user group field..
I am trying to populate logged in user in the User/Group field using Custom Object.
2019-01-14 02:58 PM
In the Application Builder in the Fields tab, hover over the field you need, and on the right bottom side you will see the ID.
2019-01-14 02:59 PM
Irfan, hover over the field on the Field tab for the application and at the very bottom right of the field listing you'll see the id (ID: nnnn).
Advisory Consultant
2019-01-14 03:29 PM
Wow that was quick. Thank you David and IIya for the reply. Awesome!!!
2019-01-18 12:54 PM
I was able to test the code today to populate a User/Group field and it worked perfectly fine in version 6.4.
Attaching the code below.
Question: How does your script appears in code format with line numbers. I couldn't find any option on the screen for it.
<img src="../BackgroundImageGenerator.axd?className=StyledButton&classProperties=caption:Add User;iconSetStyle:VistaRound;baseColor:%23DDDDDD;disabled:False" onclick="setRecordPermission()">
<script type="text/javascript">
var setUser = {
fldId: '35407',
usersName: parent.parent.ArcherApp.globals.displayName,
usersId: parent.parent.ArcherApp.globals.userId,
itemType: 'user'}; // Use 'group' if you're adding a group
function setRecordPermission() {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(setUser.fldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
UsrArray.push({
name: setUser.usersName,
value: setUser.usersId + ':' + (setUser.itemType == 'group' ? 3 : 1)
});
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="'+ RPFieldRootId +'_"] div:first-child').text(setUser.usersName);
$('input[id*="'+ RPFieldRootId +'_"]').val(serialized);
if(setUser.itemType == 'user'){
$('#SelectedUsers'+setUser.fldId).val(setUser.usersId);
}else if(setUser.itemType == 'group') {
$('#SelectedGroups'+setUser.fldId).val(setUser.usersId);
}
}
</script>