Important Update: Archer Community Scheduled Maintenance on November 23–24 - New Community Launching Soon! Learn More..
2019-04-02 09:58 AM
Hi,
I am trying to Hijack copy button by using custom object, In order to Copy some data instead of everything. When I hit copy I could able to see required fields data, but when I hit Save or (Save & Close) its not saving the current data but taking previous data and saving everything. Please find the below code , I am using archer 6.5 version. Can any one help me fixing this issue...
<script type="text/javascript">
var flag = '1';
Sys.Application.add_load(function() {
$('#master_btnCopy').click(function(){
flag ='0';
localStorage.setItem("CopyBtnflagVal", flag);
var trackingIdVal = $('#master_DefaultContent_rts_s8979_f50003c').text();
localStorage.setItem("trackingIdVal",trackingIdVal);
});
if(localStorage.getItem("CopyBtnflagVal")=='0'){
var originalTrackIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50394);
var originalTrackId = originalTrackIdRoot.clientId;
var documentStatusIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50216);
var documentStatusId = documentStatusIdRoot.clientId
var docStatusHelperIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50295);
var docStatusHelperId = docStatusHelperIdRoot.clientId;
var adminIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50389);
var adminId = adminIdRoot.clientId;
var review1IdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50328);
var review1Id = review1IdRoot.clientId;
var review2IdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50329);
var review2Id = review2IdRoot.clientId;
var review3IdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50330);
var review3Id = review3IdRoot.clientId;
var copyApprovalIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50225);
var copyApprovalId = copyApprovalIdRoot.clientId;
var approvalWorkflowIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50291);
var approvalWorkflowId = approvalWorkflowIdRoot.clientId;
var createResponseIdRoot = ArcherTech.UI.ClientContentManager.GetInstance().getFieldById(50286);
var createResponseId = createResponseIdRoot.clientId;
$("#"+review1Id+"_0").attr('checked', false);
$("#"+review1Id+"_1").attr('checked', false);
$("#"+review2Id+"_0").attr('checked', false);
$("#"+review2Id+"_1").attr('checked', false);
$("#"+review3Id+"_0").attr('checked', false);
$("#"+review3Id+"_1").attr('checked', false);
$("#"+copyApprovalId+"_0").attr('checked', false);
$("#"+copyApprovalId+"_1").attr('checked', false);
$("#"+approvalWorkflowId+"_0").attr('checked', false);
$("#"+approvalWorkflowId+"_1").attr('checked', false);
$("#"+createResponseId+"_0").attr('checked', false);
$("#"+createResponseId+"_1").attr('checked', false);
$('#'+originalTrackId).find('table').find($('tr td:first-child')).find('div').append('<span>'+localStorage.getItem('trackingIdVal')+'</span>');
$('#'+documentStatusId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
$('#'+documentStatusId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').append('<span>'+'Draft'+'</span>');
$("#subsection").find("div").find("table").children('tbody').children('tr').children('td:last-child').children('div #subsection_vSelView_pnl').find('ul').find('div').find('div:first-child').empty();
$("#subsection").find("div").find("table").children('tbody').children('tr').children('td:last-child').children('div #subsection_vSelView_pnl').find('ul').find('div').find('div:first-child').append("Draft");
$('#'+docStatusHelperId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
$('#'+adminId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
localStorage.setItem("CopyBtnflagVal", "1");
localStorage.setItem("trackingIdVal","");
}
});
function setTextField(f,v) {
var textFieldAttributes = new Array();
textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: v,
valueAsString: v,
minValue: '-9999999999999',
maxValue:'9999999999999',
lastSetTextBoxValue: v});
var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);
$('input[id$="'+ f +'c"]').val(v);
$('input[id$="'+ f +'c_ClientState"]').val(textFieldAttributesSerialised);
csp(event)
}
</script>
2019-04-02 10:03 AM
I think your code does no hijack the real Copy button, and that is executed anyways.
To check your function, create another button and check functionality of the code, then you can think on hijacking.
Maybe it is also better to vote for the idea: https://community.rsa.com/ideas/1368
And here you will see examples on how to emulate buttons and hijack them:
2019-04-02 10:12 AM
Thank you for quick response, I will look into it...
2019-04-02 10:14 AM
Another thing, that your custom code will not be able to work on CREATED/SAVED record, because you will save, and that will go in VIEW mode, and you would not be able to enter the data you needed from previous records, and clean others. Unless you immediately upon creation go to Edit, save all the data in variables, and out them. However, such solution is very unstable and depends on many factors.
I propose to use such "Copy" functionality either over API or Data Feed.
2019-04-02 11:53 AM
If this is how your setting field values:
$('#'+originalTrackId).find('table').find($('tr td:first-child')).find('div').append('<span>'+localStorage.getItem('trackingIdVal')+'</span>');
$('#'+documentStatusId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
$('#'+documentStatusId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').append('<span>'+'Draft'+'</span>');$("#subsection").find("div").find("table").children('tbody').children('tr').children('td:last-child').children('div #subsection_vSelView_pnl').find('ul').find('div').find('div:first-child').empty();
$("#subsection").find("div").find("table").children('tbody').children('tr').children('td:last-child').children('div #subsection_vSelView_pnl').find('ul').find('div').find('div:first-child').append("Draft");
$('#'+docStatusHelperId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
$('#'+adminId).find('table:last-child').find($('tr td:first-child')).find('div .SelectedOverFlowDiv').find('span').text("");
Then I can see your problem, this is not how you update fields via custom objects.
You do have the setTextField function in the custom object and that will work for text and numeric fields. Values list fields has a different way to set its value:
function UpdateValueList(changeId, assignedValue) {
var valueArray = new Array(1);
valueArray[0] = assignedValue;
$CM.setFieldValue(changeId, valueArray, '');
}
Advisory Consultant
2019-04-02 11:58 PM
Hi David Petty,
Thanks for the reply .
When I am trying to execute the code what you mentioned . I am getting the error like
"Unable to get property 'values' of undefined or null reference"
Can you please help me
2019-04-03 09:22 AM
Put in some console.log() lines in your code to see what's actually being passed; you'll need the browser developer console open to see the output. The browsers debugging tools should be able to tell you what line threw that error.
Advisory Consultant