Here’s the scenario, in case it helps: on a Contacts form, I want the user to enter the Company. If the company exists, it will link using the typeahead. If, however, the user enters a value not found in Companies, the method will go create that company, and bring back the appropriate key.
First, I’ve run into an issue (or my own incompetence) that triggers the method at the wrong time (I’ve posted that elsewhere). But let’s assume for now that the very cooperative user triggers the method after editing the company name.
The company name is actually entered into the k_comp (key, company) field, with a value list that show the company name, but returns the company key.
My method (pasted below) checks to see that they’ve chosen a valid company. If not, the method grabs the new company name, goes to the company form, creates a company, gives it the name the user entered, grabs the new key, comes back, and links the contact to the new company.
All this seems to work, except that the k_comp field now displays the company key, not the company name. If I restart the solution, or if I go into layout and back, it will display the company name again.
Is there some sort of “refresh” command I could use, or am I perhaps setting variables and fields in some way that messes with the display?
Here’s the Method (general efficiency and best practice tips are welcome, too!):
if ( !people_to_companies.pk )
if ( k_comp )
{
{
var a = k_comp
forms.companies.controller.newRecord()
forms.companies.company_name = a
var a = forms.companies.pk
k_comp = a
}
}