Making 'relate' field also allow free text

Hi,
I am using a relate field to select a contact for an invoice which works well.

However, certain people do not like having to click the select button next to it and then the create button and enter in all the data every time a new client is added, especially as this happens whilst on the phone to a new client, so isn’t much time.

Is there any way of making the relate field also allow free text and then using a logic hook to see if the record exists in address book and then create a new record if not?

Currently if one enters text not in the database then the moment you click away it all vanishes. Can I stop this behaviour?

Hi ajgisme,

This may be possible with a logic hook. Have you looked at the SugarCRM developer documentation?

Thanks,

Will.

Yes I am planning on using a logic hook for the other half of this procedure.

The problem is when someone enters text into the ‘relate’ field that isn’t in the database the field gets cleared…I need to stop this behaviour so I can implement the logic hook, that’s what I’m trying to do.

Do you mean, the sales rep is on the phone talking to the customer, types free form text in a box, does not hit save, then navigates to another page, so the text is lost. But you want to capture that text and use some smart code in a logic hook, to look thru that text, and use it to create a new Contact.

Almost. The problem isn’t saving the record. The problem is the relate field. Take the contact field in the invoices module for example. When a user starts typing a drop down menu appears of entries. This is great except if you type something that isn’t there and click on something else then the text gets erased. I need to stop this behaviour so that I can implement the logic hook to save to the contacts module if not an option from the drop down menu.

Changing that behaviour will not be easy as the JavaScript that handles it is deep within the core of sugar/suite and is heavily cached. However it should be possible to overwrite the JavaScript in a custom view for a particular module. I am not 100% sure how it works off the top of my head but you need to look into altering or overwriting the Scripts that handle the SQS objects.

Yeah I eventually found the javascript files in the cache.

I found this chunk but I can’t find which part to change to remove the behaviour:

function enableQS(noReload){YAHOO.util.Event.onDOMReady(function(){if(typeof sqs_objects==‘undefined’){return;}
var Dom=YAHOO.util.Dom;var qsFields=Dom.getElementsByClassName(‘sqsEnabled’);for(var qsField in qsFields){if(typeof qsFields[qsField]==‘function’||typeof qsFields[qsField].id==‘undefined’){continue;}
var form_id=qsFields[qsField].form.getAttribute(‘id’);if(typeof form_id==‘object’&&qsFields[qsField].form.getAttribute(‘real_id’)){form_id=qsFields[qsField].form.getAttribute(‘real_id’);}
var qs_index_id=form_id+’’+qsFields[qsField].name;if(typeof sqs_objects[qs_index_id]==‘undefined’){qs_index_id=qsFields[qsField].name;if(typeof sqs_objects[qs_index_id]==‘undefined’){continue;}}
if(QSProcessedFieldsArray[qs_index_id]){skipSTR=‘collection_0’;if(qs_index_id.lastIndexOf(skipSTR)!=(qs_index_id.length-skipSTR.length)){continue;}}
var qs_obj=sqs_objects[qs_index_id];var loaded=false;if(!document.forms[qs_obj.form]){continue;}
if(!document.forms[qs_obj.form].elements[qsFields[qsField].id].readOnly&&qs_obj[‘disable’]!=true){var combo_id=qs_obj.form+’
’+qsFields[qsField].id;if(Dom.get(combo_id+"results")){loaded=true}
if(!loaded){QSProcessedFieldsArray[qs_index_id]=true;qsFields[qsField].form_id=form_id;var sqs=sqs_objects[qs_index_id];var resultDiv=document.createElement(‘div’);resultDiv.id=combo_id+“results";Dom.insertAfter(resultDiv,qsFields[qsField]);var fields=qs_obj.field_list.slice();fields[fields.length]=“module”;var ds=new YAHOO.util.DataSource(“index.php?”,{responseType:YAHOO.util.XHRDataSource.TYPE_JSON,responseSchema:{resultsList:‘fields’,total:‘totalCount’,fields:fields,metaNode:“fields”,metaFields:{total:‘totalCount’,fields:“fields”}},connMethodPost:true});var forceSelect=!((qsFields[qsField].form&&typeof(qsFields[qsField].form)==‘object’&&qsFields[qsField].form.name==‘search_form’)||qsFields[qsField].className.match(‘sqsNoAutofill’)!=null);var search=new YAHOO.widget.AutoComplete(qsFields[qsField],resultDiv,ds,{typeAhead:forceSelect,forceSelection:forceSelect,fields:fields,sqs:sqs,animSpeed:0.25,qs_obj:qs_obj,inputElement:qsFields[qsField],generateRequest:function(sQuery){var item_id=this.inputElement.form_id+’’+this.inputElement.name;this.sqs=updateSqsFromQSFieldsArray(item_id,this.sqs);if(QSCallbacksArray[item_id]){QSCallbacksArrayitem_id;}
var out=SUGAR.util.paramsToUrl({to_pdf:‘true’,module:‘Home’,action:‘quicksearchQuery’,data:YAHOO.lang.JSON.stringify(this.sqs),query:decodeURIComponent(sQuery)});return out;},setFields:function(data,filter){this.updateFields(data,filter);},updateFields:function(data,filter){for(var i in this.fields){for(var key in this.qs_obj.field_list){if(this.fields[i]==this.qs_obj.field_list[key]&&document.forms[this.qs_obj.form].elements[this.qs_obj.populate_list[key]]&&this.qs_obj.populate_list[key].match(filter)){var displayValue=data[i].replace(/&/gi,’&’).replace(/</gi,’<’).replace(/>/gi,’>’).replace(/’/gi,’’’).replace(/”/gi,’"’);document.forms[this.qs_obj.form].elements[this.qs_obj.populate_list[key]].value=displayValue;SUGAR.util.callOnChangeListers(document.forms[this.qs_obj.form].elements[this.qs_obj.populate_list[key]]);}}}
SUGAR.util.callOnChangeListers(this.elTextbox);},clearFields:function(){for(var key in this.qs_obj.field_list){}
this.oldValue="";}});if(/^(billing
|shipping
)?account_name$/.exec(qsFields[qsField].name))

No worries, I’ve done it!
I took out the ‘forceselect’ part.