Script to include an address when a site is selected.

Script to include an address when a site is selected.

Below is an example of the script I am trying to run.

I can make it run when a ticket is edited after creation. But I need it to work when a ticket is created initially. The site field has a default entry of 'not associated to any site' when starting a ticket and this field is to be changed, I want the site address to be populated into the address field we also have when a site is selected.

I have the correct radio buttons selected in the field and form rules of 'on form load', 'on create/edit', no event, no condition, then the script selecting 'execute script'. I have also tried it using the event of 'on field change 'site', that didn't work either. I have also tried adding it directly into the form as opposed to making a global one... no change.

I have checked that SITE is exactly that (when selecting site in the options within the script tool), and that the Site Address field is CHAR37.

This is driving me insane trying to work it out. So any help anyone can offer would be amazing :-)

Can you please advise why mine will only work on edit only.

I'm on MESD 11009, with no intention to upgrade currently. We're on an air-gapped network.
______________________________________________

var y = $CS.getText("SITE") || $CS.getValue("Site");
if (!y) return;
var mapping = {
"Site Name":"Site address1, Site address1, Postcode",
"Site Name":"Site address2, Site address2, Postcode",
"Site Name":"Site address3, Site address3, Postcode",
"Site Name":"Site address4, Site address4, Postcode",
"Site Name":"Site address5, Site address5, Postcode",
};
if (mapping[y]) {
    $CS.setValue("WorkOrder_Fields_UDF_CHAR37", mapping[y]);
};

                      New to ADSelfService Plus?