Important Update: Community URLs redirect issues are partially resolved. 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.

15 REPLIES 15

Nice work Irfan

 

To format the code, highlight it and in the editor hit the ..., then select More drop-down and select Syntax highlighter

 Advisory Consultant

Hi David

Not sure if possible but is there a way to execute this code using an Advanced workflow button before "save" action?

For example if I have 2 Adv. Workflow buttons Approve and Reject and I want this code to trigger when a user clicks approve.

David Merrick knows all about it  

Unbind AWF buttons? 

Hi IIya

Thanks for the link. I was able to successfully implement it. I added function for both Approve and Reject buttons to capture the approver and rejecter and give an alert that it is rejected or approved. I'll copy the code below in case someone needs it.

 

<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     //Grab Transition tab info and store it var TransitionClickReject = $('a[title="Reject"]').prop("onclick"); var TransitionClickApprove = $('a[title="Approve"]').prop("onclick");
//Resets tab to trigger validation
Sys.Application.add_load(function() {
//Resets transition tab to validate rules $('a[title="Reject"]').removeAttr('onclick').unbind('click'); $('a[title="Reject"]').prop("onclick", null); $('a[title="Reject"]').click(function() {
RejectMethod(); });
$('a[title="Approve"]').removeAttr('onclick').unbind('click'); $('a[title="Approve"]').prop("onclick", null); $('a[title="Approve"]').click(function() {
ApproveMethod(); });
function RejectMethod() { 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); } alert("Rejected"); TransitionClickReject(); // Sending it to Transition to save record and move to next step }

function ApproveMethod() { 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); } alert("Approved"); TransitionClickApprove(); // Sending it to Transition to save record and move to next step } }); </script>

Anytime 

Hi Irfan,

I am not an expert in Java Script, so I need your help.

What items should I personalize to my system in your code? I mean, where to write specific field IDs which are custom to my environment, etc.

Thank you in advance!