Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript code to attach content id to cross reference field

gaurav_bnym
Contributor

I have a custom object that creates a subform record using content controller, now I need to attach this subform record to cross reference field. I dont want to do put call on content controller. How to achieve this using javascript.

2 REPLIES 2

archer_scripts
Contributor III

Use the newly created content ID of that subform, and call the Archer Rest API to update the record you want to attach this subform record to, I believe you have to call UPDATE on the parent record.


Innovative solutions for RSA Archer, at archerscripts.com

NiritHull
Collaborator II

This code creates from app 1, an app 3 record and adds it to the right xref field on app 2 (app 2 record is xref'd to app 1)... you can probably use some of it to do what you are looking to do:

<div class="workflow-app-buttons" id="wftran1998:CUST">
<a title="Add Record" class="tb-btn-link-left" id="btn_AddRecord" href="javascript&colon;void(0);">
<div class="tb-btn " data-icon="" data-icon-pos="left">Add Record</div>
</a>
</div>

<script type="text/javascript">
var parentApplicationId = 598; // application 'b'
var destinationApplicationId = 601; // application 'c'
var destinationApplicationLevelId = 334; // application 'c'
var parentCrossReferenceFieldId = 37220; // application 'a' cross-reference field on application 'b'
var CrossReferenceFieldId = 37032; // application 'b' cross-reference field on application 'a'
var crossReferenceContentId;
var temp;
Sys.Application.add_load(function() {
var crossReferenceContentId = JSON.parse($('input[name$="SelectedValues'+ CrossReferenceFieldId +'"]').val());
temp = String(crossReferenceContentId);
//debugger;
//console.log(crossReferenceContentId);
});

$('#btn_AddRecord').click(function (){
if (!crossReferenceContentId) {
$pb('{"a":[{"Key":"contentid","Value":"' + temp + '"},{"Key":"fieldid","Value":"' + parentCrossReferenceFieldId +'"},{"Key":"moduleId","Value":"'+ parentApplicationId+ '"},{"Key":"refmodid","Value":"' + destinationApplicationId + '"},{"Key":"levelid","Value":"' + destinationApplicationLevelId + '"},{"Key":"isSubform","Value":"False"},{"Key":"isAnswerValuesSubform","Value":"False"}],"e":"refFieldAddNew"}');
csp(event);
return false;
}
});
</script>