A new field as a combined of other fields

Hi, i have created a form to collect data of “Unit Number”, “Street No.”, “Street Name”, “Suburb”, “Postcode”. I want to show those address data in FULL as a full street on a dynamic page. What is the more effective ways to make it happen?

Is there any way that to create a new field as “Full Address” then as me combined all those field’s content into the Full Address field. I also want to add “/” between the “Unit number” and “Street No.” if there is content in “Unit Number”.

Hi,
It is possible using Data Hooks . Before Insert hook is the right one for you.
It should look like this:

function yourCollection_beforeInsert(item) {
item.fullAdress = `${item.unnitNumber}/${item.streetNumber}/${item.suburb}`;
return item;
}

Don’t forget to add a new field to the collection.
Another option is to use getCurrentItem method.
Here is a sample:

$w.onReady(() => {
    $w('#yourDataset').onReady(() => {
    const thisItem = $w('#yourDataset').getCurrentItem();
    $w('#yourFullAdressText').text = `${thisItem.unnitNumber}/${thisItem.streetNumber}/${thisItem.suburb}`;
    });
});

Good luck!
Roi

Hi Thx.

I am wondering if i will still need to create another field on the dataset as “#yourFullAdressText

Hi again,
In the second example you don’t to create another field.
Roi

Hi,


export function listings_beforeInsert(item, context) {
	//TODO: 
	
function yourCollection_beforeInsert(item) {
item.fullAdress = `${item.addressUnit}/${item.addressStreet}/${item.addressSuburb}`;
return item;
}	


}


I have add the option 1 on the hook, but why it is saying this say sentense mistake as below image

if is want the FULL ADDRESS shows as:
“addressUnit”/“addressNumber” addressStreet,
“addressSuburb”, “addressState”, “addressPostcode”

Sample as:
2/1 Thomas Street,
Doncaster, VIC 3128
“addressSuburb”, “addressState”, “addressPostcode”

Not sure how can i create the “NEXT LINE” “SPACE” and “,”

Hi,

export function listings_beforeInsert(item, context) {  
 item.fullAddress = `${item.addressUnit}/${item.addressStreet}/${item.addressSuburb}`; 
 return item;  
}

For next line:

const nextLine ="Hello \n World"; // \n

And for space just make empty character in the string
Good luck!
Roi

Now it say CONTEXT has never used. I have no idea what i should do.

Btw, i though below code

 export function listings_beforeInsert(item, context) {    item.fullAddress = `${item.addressUnit}/${item.addressStreet}/${item.addressSuburb}`; return item; } 

will show “addressUnit” / “addressStreet” / “addressSuburb” ----that means—> 2/Tomas Street/Doncaster

But i want to show 1/2 Thomas street, Doncaster, VIC 3128

thats mean —>
“addressUnit”/“addressNumber” addressStreet,
“addressSuburb”, “addressState”, “addressPostcode”

Can someone help plz

Hi,

regarding the context warning, since you are not using this variable, you can remove it from the function’s signature.
regarding the address format, you can use the item’s attributes to create all kinds of formats. use it to create the format you are aiming for.

Good luck,
Idan.

Hi sorry, i hv no idea with ur terms:
whats item’s attributes ?
wts function’s signature.?

Anyone can help to show me how to combine a few field into one output content please?

I want to show.
“addressUnit”/“addressNumber” addressStreet,
“addressSuburb”, “addressState”, “addressPostcode”

Hi,

Regarding the function warning, you can use:
“export function listings_beforeInsert(item)” instead of “export function listings_beforeInsert(item, context)” to reduce the warning.

To help you construct the address in the desired format, try using String interpolation: Template literals (Template strings) - JavaScript | MDN

Good luck,
Idan.

Thx so much Idan, i can so new for the coding. Apprecaited ur help. I have remove the warning by what you said, but the fucntion doesn’t work still. I can see i am getting there.

What sure if i am on the right track. Let me tell you guys what i have done so far.

I want to make the address look like

1 Thomas Court, Doncaster, VIC 3128
which means=
AddressNumber AddressStreet, AddressSuburb, AddressState AddressPostcode

Firstly, i hv use the code:

export function listings_beforeInsert(item){  
 item.fullAddress = `${item.addressNumber} ${item.addressStreet} \n ${item.addressSuburb} ${item.addressState},  ${item.addressPostcode}  `; 
 return item;  
}

Then i create an extra field Key called "fullAddress ".

But after that, On the field it still shows the previous coding result as image below

Hi I have capture another 3 image.

Hope everyone can understand better what i have done.

I cannot see anything wrong, but it doesn’t appear the FULL ADDRESS.

It only appear the SUBURB

Hi,

try manually adding the column for full address to the listings table, and then save your work.
As it seems, your beforeInsert function should work as you wanted.

Good luck,
Idan.

Hi Idan,

Do u mean adding the Full Address Field? I have already done that.

But the function doesn’t help to combine other content into the field of “Full Address”

its actually empty still, see the image below:

Can someone help please?!!! why it doesn’t work T_T~

SO make sure you go into the database, when in the database make sure you have “before insert checked”.