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 01:08 PM
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
2019-01-21 12:42 PM
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.
2019-01-21 12:45 PM
David Merrick knows all about it
2019-01-25 11:59 AM
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>
2019-01-25 12:03 PM
Anytime
2023-02-27 07:53 AM
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!
2024-06-26 12:08 AM
I was able to get this to successfully work in a test application without any workflow validation, but the moment I try implement this in an actual app which has rules on the transition, if the rules aren't met I just get an unexpected error, rather than seeing the validation message. Does anyone else utilising this code experience the same and have any workaround other than just removing the rule from the transition?
The only real change I made to the code was that using the title to find the button wasn't working so I have to directly reference the button ID, but other than that it's the same. (I'm only utilising the 'ApproveMethod' while testing)
<script type_="text/javascript">
var setUser = {
fldId: '31767',
usersName: parent.parent.ArcherApp.globals.displayName,
usersId: parent.parent.ArcherApp.globals.userId,
//itemType can be 'user' or 'group', change depending on needs
itemType: 'user'};
console.log(setUser);
//Grab Transition tab info and store it
var TransitionClickReject = $('a[title="Reject"]').prop("onclick");
var TransitionClickApprove = $('a[id="master_26228:CUST"]').prop("onclick");
//Resets tab to trigger validation
Sys.Application.add_load(function() {
//Resets transition tab to validate rules
console.log("Loaded");
$('a[title="Reject"]').removeAttr('onclick').unbind('click');
$('a[title="Reject"]').prop("onclick", null);
$('a[title="Reject"]').click(function() {
RejectMethod();
});
$('a[id="master_26228:CUST"]').removeAttr('onclick').unbind('click');
$('a[id="master_26228:CUST"]').prop("onclick", null);
$('a[id="master_26228:CUST"]').click(function() {
ApproveMethod();
});
function RejectMethod() {
console.log("Reject");
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();
}
function ApproveMethod() {
console.log("Approve");
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();
}
});
</script>