Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2024-10-11 03:43 PM - edited 2024-10-15 05:07 PM
Hi,
The code below works perfectly fine when setting the record permission field.
But when resetting the selection from the cross reference, the record permission field is cleared after clicking the save button, but when exiting the record to view mode, the record permission field retains the previous value as if the value was not cleared/reset. It a weird behavior.
function AssignUser() {
UserArr = [];
var selectedUserId = $('input[name*="SelectedValues' + fldIds.SelectUser + '"]').val();
if (selectedUserId != '[]') {
var selUserId = selectedUserId.substring(1, selectedUserId.length - 1);
userId = GetAssociatedContactUser(selUserId);
UserArr.push({
id: userId,
name: ""
});
}
GetUserName(UserArr);
SetRecordPermission(UserArr, FieldId, 'user');
}
function GetUserName(userArr) {
var i;
for (i = 0; i < userArr.length; i++) {
var url = baseURL + "/api/core/system/user/" + userArr[i].id;
var headers = {
'x-csrf-token': csrfToken
};
$.ajax({
headers: headers,
url: url,
data: '',
type: 'GET',
contentType: 'application/json',
processData: false,
async: false,
dataType: 'json',
success: function (data, textStatus, jqXHR) {
//alert(JSON.stringify(data.RequestedObject, undefined, 2));
userArr[i].name = data.RequestedObject.DisplayName;
},
error: function (data, textStatus, jqXHR) {
alert(JSON.stringify(data, undefined, 2));
}
});
}
}
function SetRecordPermission(buStaff, flId, itemType) {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(flId),
UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
var displayNames = "";
var ids = "";
var i;
for (i = 0; i < buStaff.length; i++) {
UsrArray.push({
name: buStaff[i].name,
value: buStaff[i].id + ":" + (itemType == "group" ? 2 : 1)
});
displayNames += buStaff[i].name + " ";
ids += buStaff[i].id + ",";
}
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
ids = ids.substring(0, ids.lastIndexOf(','));
//alert(serialized);
$('input[id*="' + RPFieldRootId + '_"]').val(serialized);
$('div[id*="' + RPFieldRootId + '_"] div:first-child').text(displayNames);
if (itemType == "group") {
$('#SelectedGroups' + flId).val(ids);
} else {
$('#SelectedUsers' + flId).val(ids);
}
}
function GetAssociatedContactUser(ctId) {
var id = 0;
var userid;
var url = baseURL + "/api/core/content/" + ctId;
var headers = {
'x-csrf-token': csrfToken
};
$.ajax({
headers: headers,
url: url,
data: '',
type: 'GET',
contentType: 'application/json',
processData: false,
async: false,
dataType: 'json',
success: function (data, textStatus, jqXHR) {
userid = data.RequestedObject.FieldContents[fldIds.RSAArcherUserAccountCT].Value;
},
error: function (data, textStatus, jqXHR) {
alert(JSON.stringify(data, undefined, 2));
}
});
if (userid !== null && userid !== 'undefined')
return userid.UserList[0].Id;
else
return id;
}
});
2024-10-13 03:20 AM
Try Resetting the RP field explicitly
function ResetRecordPermission(flId) {
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(flId);
var RPFieldRootId = RPFieldRoot.clientId;
// Clear the input and display fields
$('input[id*="' + RPFieldRootId + '_"]').val('');
$('div[id*="' + RPFieldRootId + '_"] div:first-child').text('');
$('#SelectedUsers' + flId).val('');
$('#SelectedGroups' + flId).val('');
}
2024-10-15 11:51 AM
Thank you @squarabh .
That didn't work, and didn't reset the RP field.
The code I posted resets the RP field on the screen after the Save button, but when exiting the record to View mode, the value of RP field will still be there.
Thank you
2024-10-16 10:18 AM
@Archerwizz2022 in your SetRecordPermission, replace
$('input[id*="' + RPFieldRootId + '_"]').val(serialized);
$('div[id*="' + RPFieldRootId + '_"] div:first-child').text(displayNames);
if (itemType == "group") {
$('#SelectedGroups' + flId).val(ids);
} else {
$('#SelectedUsers' + flId).val(ids);
}
With
$.each(UsrArray, function(key,value){
var isLastItem = (key == (UsrArray.length -1));
selectedUsers+=value.name;
if (!isLastItem) selectedUsers+="<br>";
selectedUsersId+=value.value.split(':')[0]
if (!isLastItem) selectedUsersId+=",";
});
$('div[id*="'+ RPFieldRootId.clientId +'_"] div:first-child').html(selectedUsers);
$('input[id*="'+ RPFieldRootId.clientId +'_"]').val(serialized);
$('input[id*="SelectedUsers'+ fld +'"]').val(selectedUsersId);
var usersGroups = $CM.getFieldControl($CM._fields[fld])
var tree = $find(usersGroups.get_treeViewId());
tree.set_popupValue(UsrArray);
Advisory Consultant
2024-10-16 11:10 AM
Thank you @DavidPetty .
I tried your code and it does the same behavior like my code, where the record permission field's value gets reset on clicking the Save button, but when I exit from the record, the existing value still shows up on the field.
Worth mentioning that the RP field is set as "Values Popup" and Configuration is set to 1 as Maximum Selection and "No Minimum" and Permission Model is "Manual".
Field Population is Update and Show Users checked. No rules are added.
2024-10-16 11:30 AM
Odd... Are there any errors being thrown in the developer tools console?
Advisory Consultant
2024-10-16 11:42 AM
I agree it's odd.
No, no errors were thrown in either cases.
2024-10-28 04:21 PM
Do you think if this is a defect/bug in Archer? Or is there any thing else I can change?
2024-10-30 08:43 AM
No, being I've been using the code I posted above without any problems.
What version of Archer are you on?
Advisory Consultant
2024-10-30 09:04 AM
I believe it used to be working without any issues previously as well.
SaaS
Version: 2024.09
Build: 6.15.00302.10262