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: 

Help with CO to clear a text field

ScottNess1
Contributor III

I'm trying to build out a custom object in 6.9 P2 that will clear the value in a text field based on the value selected from a values list field.

I've read through article https://community.rsa.com/t5/archer-custom-objects/clear-out-text-field-based-on-value-list-options/td-p/453479 a number of times, but seem to be stuck.

The error in console is 'SCRIPT5009: 'fld' is undefined  It seems to be related to this line of code - var vlClientId = $CM.getFieldById(fld.vlField).clientId;

 

The full code is - 

<script type="text/javascript">
const vlField = 120601; // Values List Field Classification
const textFields = 123788; // Text field Exam Name
const clearOnValues = ['138716:0']; // Value from Classification = Simple
function setTextField(fld,val)
{
var textFieldAttributes = new Array();
textFieldAttributes.push({
enabled: true,
emptyMessage: '',
validationText: val,
valueAsString: val,
lastSetTextBoxValue: val});
console.log("Values list Field ID: "+ vlField);
console.log("Test Field ID: "+ textFields);

var textFieldAttributesSerialised = Sys.Serialization.JavaScriptSerializer.serialize(textFieldAttributes[0]);
$('input[id$="'+ fld +'c"]').val(val);
$('input[id$="'+ fld +'c_ClientState"]').val(textFieldAttributesSerialised);
console.log("in set text function");
console.log("fld = ", fld);
console.log("val = ", val);
}
Sys.Application.add_load(function()
{
var vlClientId = $CM.getFieldById(fld.vlField).clientId;
$('div[id^="' + vlClientId + '"]').change(function()
{
var selectedValue = $CM.getFieldValue(fld.vlField);
if (selectedValue !== null && fld.clearOnValues.indexOf(selectedValue[0]) !== -1)
console.log("Clearing Text Field");
{setTextField(textFld, '');
}
});
});
</script>

The values list field is dropdown.

Appreciate any suggestions/guidance on what I may be missing.

TIA

 

18 REPLIES 18

What if we need to clear the text field and at the same time the same field which is being cleared also need to be readonly. please suggest, tried to use below two separately to set to readonly but none is working

document.getElementById('id').setAttribute('readonly', true);
document.getElementById('id').readOnly = true;

@VirenGupta you can use this function to set a text field that is read-only, Re: Populate a Read Only field with JavaScript? - Archer Community - 448551 (archerirm.community)

 Advisory Consultant

With this function as well, able to clear the text field value but not able to make the field readonly. please suggest how to update the function so that the field can be cleared and at the same time can make it readonly. As soon as the field has no value then it should be readonly too. I tried to do by DDEs and also setting the readonly property but in that case clearing the text field does not work. 

Setting a field as read-only is done by a DDE and that function will set/clear a text field with no problems.

 Advisory Consultant

I tried to set a DDE to make the field readonly which we are clearing using the function, though if the DDE makes the field readonly then the function does not clear out the field. if i disable the readonly DDE then the function works

I need to do both the actions at the same time clearing the text field value and making it readonly. the field is not already a readonly, its editable. There are 2 text fields, if a user enters the value as zero in text1 field then this should clear the text2 field value and make it readonly at the same time. 

What version of Archer are you on?

 Advisory Consultant

6.14 P1 HF4

@DavidPetty - the code using getelementid which i used earlier was working , i didnt notice as this does not look similar what we see as readonly for a field on layout. It disabled the field (below screenshot) and user cant enter the value in the field. I think this solves the purpose without using DDE and with the custom code itself. Thanks 

VirenGupta_0-1716397817863.png