Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2020-11-09 12:24 PM
Using Archer 6.8 P2. Found the following code from Archer Community to remove a user from record permission field:
function setUser(userFldId, userName, userId) {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(userFldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
UsrArray.push({
name: userName,
value: userId + ':1'
});
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="'+ RPFieldRootId +'_"] div:first-child').text(userName);
$('input[id*="'+ RPFieldRootId +'_"]').val(serialized);
$('#SelectedUsers'+userFldId).val(userId);
}
Then call the function using field ID, blank user name (''), and blank user ID (''). Looks like the user gets removed. But when trying to add a new user, noticed that there is a blank user in the field:
Since the field only allows 1 user, new user cannot be added before remove this blank user first.
Can anyone help solve this problem? Thanks.
2020-11-09 03:08 PM
Thanks, try this verson:
function setUser(userFldId, userName, userId) {
var setUser = {
fldId: userFldId,
userName: userName,
userId: userId,
itemType: 'user'
}
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(userFldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
if(setUser.userId != '') {
UsrArray.push({
name: userName,
value: userId + ':1'
});
}
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="'+ RPFieldRootId +'_"] div:first-child').text(setUser.userName);
$('input[id*="'+ RPFieldRootId +'_"]').val(serialized);
if(setUser.itemType == 'user') {
$('#SelectedUsers'+setUser.userFldId).val(setUser.userId);
}else if(setUser.itemType == 'group') {
$('#SelectedGroups'+setUser.userFldId).val(setUser.userId);
}
}
Advisory Consultant
2020-11-09 12:29 PM
Xiang, can you post the complete custom object that clears the record permission field?
Advisory Consultant
2020-11-09 02:41 PM
Hi David,
The code to display a button is:
<style>
.but {
background-color: #607d8b;
border: 3px;
padding: 5px;
margin-left: 25px;
margin-top: 5px;
margin-bottom: 5px;
font-weight: bold;
color: white;
}
</style>
<INPUT onclick=ReactivateRequest(); data-check-dirty="true" value=" Reactivate / Undo Completion " type=button class="but" name=ReactivateUndoCompletion>
The function ReactivateRequest() has the following code:
function ReactivateRequest(){
var fldCompletionDateId = lookupFieldId("Initiative Completion Date");
var fldMarkedDateId = lookupFieldId("Date Marked Complete");
var fldCommentaryId = lookupFieldId("Completion Commentary (Optional)");
var fldRecordById = lookupFieldId("Completion Recorded By");
var fldStatusId = lookupFieldId("Initiative Status");
var valueID = '47620';
$CM.setFieldValue(fldCompletionDateId, null, ''); //clear Date
$CM.setFieldValue(fldMarkedDateId, null, ''); //clear Date
setUser(fldRecordById, '', ''); //remove user from record permission field
UpdateValueList(fldStatusId, valueID); //change status to Active
setTextField(fldCommentaryId,''); //clear text
}
All others are working fine except for setUser() function call.
2020-11-09 03:08 PM
Thanks, try this verson:
function setUser(userFldId, userName, userId) {
var setUser = {
fldId: userFldId,
userName: userName,
userId: userId,
itemType: 'user'
}
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(userFldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
if(setUser.userId != '') {
UsrArray.push({
name: userName,
value: userId + ':1'
});
}
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="'+ RPFieldRootId +'_"] div:first-child').text(setUser.userName);
$('input[id*="'+ RPFieldRootId +'_"]').val(serialized);
if(setUser.itemType == 'user') {
$('#SelectedUsers'+setUser.userFldId).val(setUser.userId);
}else if(setUser.itemType == 'group') {
$('#SelectedGroups'+setUser.userFldId).val(setUser.userId);
}
}
Advisory Consultant
2020-11-09 04:13 PM
Hi David,
This one worked! Thank you very much for your help!