Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Object to Get Current User name into a Text field

Irfan_Khan
Collaborator II

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.

1 ACCEPTED SOLUTION

Accepted Solutions

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>  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

15 REPLIES 15

Ilya_Khen
Champion III

Use Global variables:

ArcherApp.globals.firstName
ArcherApp.globals.lastName‍‍

 

You should use it in Custom Object as:

parent.parent.ArcherApp.globals.firstName;

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?

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

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. Capture.JPG

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.

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

Wow that was quick. Thank you David and IIya for the reply. Awesome!!! 

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>  ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍