Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Update text field during save within Custom Object API call

Michael
Contributor

We currently have a request to consolidate the values within 4 cross-reference fields into a single text field for display only.  To accomplish this, we have created an external C# API function which will read the CR fields and return the expected display string.  Unfortunately, during the save of the record, the display text field is not being saved appropriately.

For example:
Cross-References:
1. Source Record (SR1) to Cross-Reference A (CRA)
2. Source Record (SR1) to Cross-Reference B (CRB1) and Cross-Reference B (CRB2)

Display Text within Source Record 1:
1 - CRA
2 - CRB1, CRB2

Within the custom object, the ability to either override or create a new Save button is available and complete.  The call to the external API is executed and the display string is returned.  The issue lies in having the asynchronous (API call) return before the save is complete to ensure the display text field is updated.

Any thoughts or examples?

8 REPLIES 8

Ilya_Khen
Champion III

Michael,

I believe if you call API via AJAX call, such calls can be made synchronous. 

DavidPetty
Archer Employee
Archer Employee

@Michael, is it really C# or JavaScript?

You should be able to make the API call synchronously and upon successful completion to issue the save.

 Advisory Consultant

Michael
Contributor

@DavidPetty - the custom object is written using JavaScript.  The external custom API being called is written in C#.

Are there any examples of making the API call synchronously?  I have tried using the async: false parameter, but it still appears to execute as an asynchronous call.

Ilya_Khen
Champion III

https://api.jquery.com/jquery.ajax/

async: false is the exact parameter.

Can you post the custom object you're using?

 Advisory Consultant

Michael
Contributor

Here is the custom object - it appears to update the text value, but will not save afterwards (actually it appears to save, load, then tries to save once again which never finishes)

<script type="text/javascript">
var textFieldID = 12707;

Sys.Application.add_load(function() {
$('#master_btnApply1').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply1');
$('#master_btnApply1').hide();
$('#master_customBtnApply').unbind('click').prop("onclick", null).click(function(){ UpdateRACIRole('Apply'); return false;});

$('#master_btnSave1').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave1');
$('#master_btnSave1').hide();
$('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ UpdateRACIRole('Save'); return false;});
});

function UpdateRACIRole( action ) {
var raciRole = $.ajax({
url: window.location.protocol + '//' + window.location.hostname + '/ArcherRole/api/Role/' + getRecordId(),
type: 'GET',
async: false,
contentType: 'application/json',
dataType: 'text',
success: function (data) {
setTextField(textFieldID, data.replace(/^"|"$/g, ''));
if (action == 'Save') {
$('#master_btnSave1').click();
} else if (action == 'Apply' ) {
$('#master_btnApply1').click();
}
return 'success';
}
});
};

function setTextField(fldId,val) {
var textFieldAttributes = new Array();
textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: val,
valueAsString: val,
minValue: '-9999999999999',
maxValue:'9999999999999',
lastSetTextBoxValue: val});
var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);
$('input[id$="'+ fldId +'c"]').val(val);
$('input[id$="'+ fldId +'c_ClientState"]').val(textFieldAttributesSerialised);
csp(event);
};
</script>

@Ilya_Khen, @DavidPetty - I appreciate all the assistance thus far on this issue.

Do either of you have any suggestion how to handle the save issue that I am encountering?  Using the code posted it appears to save the record, re-load the record, than attempts to save once again.  However, the last save never finishes.

Try moving the save/apply functionality to the setTextField() function instead.

 Advisory Consultant