Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2022-07-14 12:38 PM
We are getting closer but still struggling with this a bit.
The input field with the RPFieldRoot id has its value successfully updated to be the same user list, minus the duplicates, but the user field itself still has the duplicates in it on page load.
Thank you
Here's our script if anything pops out:
function getUsers() {
var primaryDiv = document.getElementById("master_DefaultContent_rts_s6032_f22161c");
var secondaryDiv = document.getElementById("master_DefaultContent_rts_s6032_f22160c");
if (primaryDiv === undefined || primaryDiv === null || secondaryDiv === undefined || secondaryDiv === null) {
console.log("Some div was null");
console.log("Primary div: " + primaryDiv);
console.log("Secondary div: " + secondaryDiv);
return null;
}
var primaryListItems = primaryDiv.getElementsByTagName("ul")[0].getElementsByTagName("li");
var secondaryListItems = secondaryDiv.getElementsByTagName("ul")[0].getElementsByTagName("li");
let count = 0;
let secondariesToRemove = [];
let index = 0;
for (let primaryListItem of primaryListItems) {
if (primaryListItem === undefined || primaryListItem === null) {
console.log("Primary list item was null or undefined");
continue;
}
let primaryAnchor = primaryListItem.getElementsByTagName("div")[0].getElementsByTagName("a")[0];
if (primaryAnchor === undefined) {
console.log("Primary anchor was null or undefined");
break;
}
let primaryHref = primaryAnchor.getAttribute("href");
for (let secondaryListItem of secondaryListItems) {
let secondaryAnchor = secondaryListItem.getElementsByTagName("div")[0].getElementsByTagName("a")[0];
if (secondaryAnchor === undefined) {
console.log("Secondary anchor was null or undefined");
break;
}
let secondaryHref = secondaryAnchor.getAttribute("href");
count++;
if (primaryHref === secondaryHref) {
console.log("HREF before substring: " + secondaryHref);
let tmp = secondaryHref.substring(78);
tmp = tmp.substring(0, 5);
secondariesToRemove[index] = tmp;
index++;
console.log("Href after substring: " + tmp);
}
}
}
return secondariesToRemove;
}
function setUsers(userFldId, secondariesToRemove) {
console.log("In setUser...");
var RPFieldRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(userFldId), UsrArray = [];
var RPFieldRootId = RPFieldRoot.clientId;
console.log("RPFieldRootId: " + RPFieldRootId);
let existingUsersText = $('input[id*="' + RPFieldRootId + '_"]').val();
let addedUserIds = [];
const existingUsers = JSON.parse(existingUsersText);
console.log(existingUsers);
for (let user of existingUsers) {
console.log(user);
let foundMatch = false;
for (let secondaryToRemove of secondariesToRemove) {
if (user.value === secondaryToRemove+":1") {
console.log("Found match: " + user.value + " " + user.name);
foundMatch = true;
break;
}
}
if (!foundMatch) {
UsrArray.push(user);
addedUserIds.push(user.value.substring(0, 5));
}
}
var serialized = Sys.Serialization.JavaScriptSerializer.serialize(UsrArray);
$('div[id*="' + RPFieldRootId + '_"] div:first-child').text('');
$('input[id*="' + RPFieldRootId + '_"]').val(serialized);
$('#SelectedUsers22361').val(addedUserIds);
}
Sys.Application.add_load(function () {
let secondariesToRemove = getUsers();
if (secondariesToRemove !== null) {
setUsers(22361, secondariesToRemove);
} else {
console.log("Found no secondaries to remove");
}
alert('script loaded');
});