cancel
Showing results for 
Search instead for 
Did you mean: 

Copy Record Permission Field to another Record Permission Field

FaisalKhan
Contributor III

Hi All,

I have a situation where I have a Manual Record Permission Field, I want to copy the list of users to another Record Permission field on save or on change

Thanks in advance

9 REPLIES 9

FaisalKhan
Contributor III

Ilya KhenDavid Petty‌ would certainly appreciate your help

FaisalKhan
Contributor III

Thank you Ilya Khen‌ but I have to read all the users from one manual RecordPermission Field and copy all the users to another RecordPermission Field.  

FaisalKhan
Contributor III

I need to read all the users from 1 Record permission field and populate the other record permission field...

any ideas?

can anyone look into it?

GeoffTaylor2
Contributor III

This will copy the users/groups from one RP field to another RP field when the user clicks Save or Save and Close.

Just change copyFromRP to the ID of the field to copy from, and change copyToRP to the ID of the field to copy to.

 

<script>
const copyFromRP = 21597; // ID of the "copy from" RP field
const copyToRP = 21598; // ID of the "copy to" RP field

function copyRP(action) {
// Get the client ID of the "copy from" field
const copyFromClient = $CM.getFieldById(copyFromRP).clientId;

// Get the client ID of the "copy to" field
const copyToClient = $CM.getFieldById(copyToRP).clientId;

/* Get the "copy from" input element's value.
It will be a serialized array of objects like this:
'[{"name":"Doe, John","value":"201:1"},{"name":"Doe, Jane","value":"202:1"},{"name":"Managers","value":"101:2"}]' */

const copyFromInputVal = $('input#' + copyFromClient + '_shf').val();

/* Get the "copy from" field's value.
It will be an array like ['201:1', '202:1', '101:2'] */

const copyFromFieldVal = $CM.getFieldValue(copyFromRP);

/* Iterate over the array, find the user and group IDs, and remove the user/group indicator.
':1' indicates a user and ':2' indicates a group. */

let copyFromSelectedUsers = Array();
let copyFromSelectedGroups = Array();

copyFromFieldVal.forEach(function(item) {
let id = item.substring(0, item.indexOf(':'));
let indicator = item.slice(-1);

if (indicator === '1') {
copyFromSelectedUsers.push(id);
}
else if (indicator === '2') {
copyFromSelectedGroups.push(id);
}
});

// Concatenate the user IDs (if any) and set the value of "SelectedUsers" hidden <input> element
if (copyFromSelectedUsers.length > 0) {
const selectedUsers = copyFromSelectedUsers.join(',');
$('input#SelectedUsers' + copyToRP).val(selectedUsers);
}

// Concatenate the group IDs (if any) and set the value of "SelectedGroups" hidden <input> element
if (copyFromSelectedGroups.length > 0) {
const selectedGroups = copyFromSelectedGroups.join(',');
$('input#SelectedGroups' + copyToRP).val(selectedGroups);
}

// Set the value of the "copy to" RP field's hidden <input> element
$('input#' + copyToClient + '_shf').val(copyFromInputVal);

// Save the record
if (action === 'save') {
$('#master_btnSave').click();
}
else if (action === 'apply') {
$('#master_btnApply').click();
}
}

Sys.Application.add_load(function() {
// Hijack Save and Close Button
$('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave');
$('#master_btnSave').hide();
$('#master_customBtnSave').unbind('click').prop('onclick', null).click(function(){ copyRP('save');return false; });

// Hijack Save Button
$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop('onclick', null).click(function(){ copyRP('apply');return false; });
});
</script>

Hi Geoff,

Thank you

You're welcome!

Hi Geff,

 

Happy new year

I was using the same code for copying from an Inherited Record permission to a Manual record permission but it was not copying it, its working fine for copying from Manual record permission to another Manual Record Permission, any suggestions?

 

Thanks in advance