How to clear value of a 'sn-record-picker' on click of a button

RevathiV
Giga Expert

I have a sn-record-picker and I have a Clear button. I want to clear the value of sn-record-picker onclick of the button.

I am also using this Clear button to clear the value of other label fields as well.

 

Code for sn-record-picker:

<sn-record-picker id="contract" name="contract" field="c.loc" table="'country'" display-field="'country.name'" display-fields="'sys_class_name'" value-field="'sys_id'" search-fields="'country.name'" page-size="20" multiple="false" ng-change="cichanged()"></sn-record-picker>

 

Code for Clear Button:
<input type="button" class="btn btn-primary btn-block text-overflow-ellipsis ng-binding ng-scope button" id="button1" style="width:100px" onclick="myFunction()" value="Clear Data">

<script>
function myFunction() {

document.getElementById("contract").value='';
}
</script>

 

Could you please help me with this.

 

Many Thanks

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@RevathiV 

where are you using this?

why not use the client controller to clear?

Can you share your complete business requirement for this?

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I am using the sn-record-picker in Angular ng-template which is linked to a widget. 

Here I have a Clear button and I'm trying to clear the value entered