Skip to main content
Known Participant
October 9, 2024
Answered

If/else AND merge fields at the same time

  • October 9, 2024
  • 2 replies
  • 542 views

Todays call for help please

 

I have seperate fields for Installation Postcode, Installation City, Billing Postcode and Billing City.

I need to merge the installation postcode and city and pull that into a different field, BUT if there is something in the Billing Postcode and City, it needs to merge and pull those details instead.

 

I've worked out how to merge the fields and I can pull either the postcode or the city across, but I can't for the life of me work out how to get it to do everything at once!

 

These are the variables

var BillingPC = this.getField("Master.ACCOUNT_BILLINGPOSTALCODE").valueAsString;

var BillingCity = this.getField("Master.ACCOUNT_BILLINGCITY").valueAsString;

var InstalPC = this.getField("installation post code").valueAsString;

var InstalCity = this.getField("installation city").valueAsString;

 

Can anyone show me how to do this. Thank you

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer JR Boulay

Place this script as a calculation script in the field that hold the merged data:

 

var str1 = "";
var str2 = "";
var BillingPC = this.getField("Master.ACCOUNT_BILLINGPOSTALCODE");
var BillingCity = this.getField("Master.ACCOUNT_BILLINGCITY");
var InstalPC = this.getField("installation post code");
var InstalCity = this.getField("installation city");

if (BillingPC.value != BillingPC.defaultValue) {str1 = BillingPC.value;}
else {str1 = InstalPC.value;}
if (BillingCity.value != BillingCity.defaultValue) {str2 = BillingCity.value;}
else {str2 = InstalCity.value;}

event.target.value = str1 + " " + str2;

 

2 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
October 9, 2024

Place this script as a calculation script in the field that hold the merged data:

 

var str1 = "";
var str2 = "";
var BillingPC = this.getField("Master.ACCOUNT_BILLINGPOSTALCODE");
var BillingCity = this.getField("Master.ACCOUNT_BILLINGCITY");
var InstalPC = this.getField("installation post code");
var InstalCity = this.getField("installation city");

if (BillingPC.value != BillingPC.defaultValue) {str1 = BillingPC.value;}
else {str1 = InstalPC.value;}
if (BillingCity.value != BillingCity.defaultValue) {str2 = BillingCity.value;}
else {str2 = InstalCity.value;}

event.target.value = str1 + " " + str2;

 

Acrobate du PDF, InDesigner et Photoshopographe
jlehaneAuthor
Known Participant
October 9, 2024

Perfect, thank you so much @JR Boulay