How to Put Restriction for Work notes Characters length?

siva44
Tera Contributor

I have created one onsubmit client script for checking work notes text atleast 20 characters else not abel to submit the form it is working fine whenever submit the form but not working whenever using post button under work notes then directly updated the work notes not checking the length

 

script:

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var worknotes=g_form.getValue('work_notes');
   if(worknotes !=''){
    if(g_form.getValue('work_notes').length < 20){
        g_form.showFieldMsg('work_notes', 'Minimum entry is 20 characters. Please add some info', 'error', true);
        return false;
    }}
}
3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

That Post button is a sticky wicket.  You can get rid of the Client Script.  In the example of the Work Notes field on the incident table, what you need is 2 Business Rules to prevent the journal entry table record from being created, then to delete the activity filter record which shows the work note was added, even though there's no journal entry for it.  This will also work when updating the incident record and not using the Post button.

 

The first Business Rule is on the sys_journal_field table, before Insert and Update:

(function executeRule(current, previous /*null when async*/) {
	if (current.value.toString().length < 20) {
		current.setAbortAction(true);
	}
})(current, previous);

 

The second Business Rule is on the sys_history_set table, after Insert and Update with the Filter Conditions = Table is incident:

(function executeRule(current, previous /*null when async*/) {
	var histGR = new GlideRecord('sys_history_line');
	histGR.addQuery('set.id', current.id);
	histGR.addQuery('field', 'work_notes');
	histGR.addQuery('type', 'audit');
	histGR.orderByDesc('update_time');
	histGR.query();
	while (histGR.next()) {
		if (histGR.getValue('new').length < 20) {
			histGR.deleteRecord();
		}
	}
})(current, previous);

 

Hi @Brad Bowman   There is any possiable the restriction  for post button 

You can hide it when this form loads or something changes.  This uses DOM manipulation, so ensure the Isolate script box is unchecked after the script is saved.

function onLoad() {
	var postBtn = document.getElementsByClassName('activity-submit');
	postBtn[0].hide();
}