Two fields with same name?

subhani6
Tera Contributor

Hi,

I have two fields with same name (company) one is reference field another is string field.Based on some conditions i need to auto populate reference field value in string field.

condition:

1. if company field(string) is empty:

what i chosen in company field(reference) that need to auto populate in company field(string).

2. if company field(string) is not empty:

what i chosen in company field(reference) that not need to auto populate in company field(string).

 

Can any one help me how can i achive this?

1 ACCEPTED SOLUTION

Try replacing

 var companyis = g_form.getValue('companyref');
    if (companyis != '') {

with

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var companyis = g_form.getValue('companyref');
var companystris=g_form.getValue('companystring');//replace companystring field correctly
if(companystris=='') //execute below only if company string is empty
{   
 if (companyis != '') {

        var compis = g_form.getReference('companyref', callback); //Replace companyref with correct field name for reference

        function callback(compis) {
            g_form.setValue('companystring', compis.name);

        }
    } 

else { //if companyis empty then clear value for companystring
        g_form.clearValue('companystring'); //Replace correct string field name for company
    }

}
}

View solution in original post

6 REPLIES 6

Willem
Giga Sage
Giga Sage

Before Insert Business rule:

if(!current.u_companyStrField){
    current.u_companyStrField = current.company.getDisplayValue()
}

This will check before the record is updated if your custom field (in above "u_companyStrField") is empty. If it is, it will set the value equal to the value of company (the display value so you can read it).

 

Let me know if it helped and please mark as Correct and Helpfull! 🙂

Jaspal Singh
Mega Patron
Mega Patron

Hi Subhani,

 

You can use an onChange() client script that runs on company field (reference) as below. Just ensure you replace the companyref & companystring field with proper field names for reference & string.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var companyis = g_form.getValue('companyref');
    if (companyis != '') {

        var compis = g_form.getReference('companyref', callback); //Replace companyref with correct field name for reference

        function callback(compis) {
            g_form.setValue('companystring', compis.name);

        }
    } 

else { //if companyis empty then clear value for companystring
        g_form.clearValue('companystring'); //Replace correct string field name for company
    }


}

 

If its for Variables then you need to use Catalog Client Script

Hi Jaspal,

Thank you for your responce.

I am using  this script based on companyref field companystring is autopopulating if companystring is empty.

But some times companystring field have some value those time also exhisting companystring value is changing.these case it should not change.

Try replacing

 var companyis = g_form.getValue('companyref');
    if (companyis != '') {

with

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var companyis = g_form.getValue('companyref');
var companystris=g_form.getValue('companystring');//replace companystring field correctly
if(companystris=='') //execute below only if company string is empty
{   
 if (companyis != '') {

        var compis = g_form.getReference('companyref', callback); //Replace companyref with correct field name for reference

        function callback(compis) {
            g_form.setValue('companystring', compis.name);

        }
    } 

else { //if companyis empty then clear value for companystring
        g_form.clearValue('companystring'); //Replace correct string field name for company
    }

}
}