Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable To Reset Record Permission Field using Custom Object

Archerwizz2022
Contributor III

 

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.

@DavidPetty 
@Ilya_Khen 

 

 

 

 

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;
}
});

 

 

 

 

 

9 REPLIES 9

squarabh
Contributor III

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('');
}

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

DavidPetty
Archer Employee
Archer Employee

@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

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.

Odd...  Are there any errors being thrown in the developer tools console?

 Advisory Consultant

I agree it's odd.

No, no errors were thrown in either cases.

Do you think if this is a defect/bug in Archer? Or is there any thing else I can change?

No, being I've been using the code I posted above without any problems.

What version of Archer are you on?

 Advisory Consultant

I believe it used to be working without any issues previously as well.

SaaS

Version: 2024.09
Build: 6.15.00302.10262