- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 03:12 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 04:10 AM
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
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 03:17 AM
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! 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 03:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 04:02 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2020 04:10 AM
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
}
}
}