Get additional columns from lookup item
In this scenario we have a New/Edit form that includes a lookup column, we want to display additional columns from the lookup list as R/O fields that get updated when user changes the selected lookup item.
example: In the following purchase order form, we have the "Select Vendor" lookup column:
The requirement: when user selects a vendor in the lookup column, the "Vendor phone" and "Vendor email" fields should be automatically updated with the selected vendor's phone and emails, and also appear as R/O.
To implement this scenario, select the "Get additional information from lookup item" sample code:
We need to update the variables which appear at the beginning part of the script according to the column names we have in our list.
In our example, we have to change the following variable values:
var lookupFieldName- update the name of your lookup column ("Select Vendor" in our example)
var fieldsToGet- this is an array of names of the lookup columns you want to get their valkue from the lookup list (["Email", "Phone"] in our example)
var fieldsToSet - this is an array of field names in our form that you want to update with the retrieved values from the lookup list, ["Vendor Email", "Vendor phone"] in our example.
The second script we should add is "Make the target fields appear read-only", which enables setting requested fields to be displayed as read-only fields. After you select that script, you need to update the following variable value to:
var
fieldsToDisable= [
"Vendor email"
,
"Vendor phone"
]
IMPORTANT: you need to use the internal column names, which might be different than their displayed names.
After you update the variable values in the script, save it and refresh the form. Now everytime user selects a vendor, the Vendor phone and Vendor email fields get updated with the selected vendor's phone and email values, and appear as R/O fields:
"Live" calculated fields
In this scenario we have a New/Edit form, where some fields should behave as calculated fields. Unlike SharePoint out-of-the-box calculated fields which do not appear on New/Edit forms and are updated only when you save the item, in our case these are "Live" calculated fields, so they get updated immediatelly when user updates other fields on which the calculated fields depend.
example: In the following Order form, we have the "Total" column:
The requirement: when user updates the Quantity and Price fields, the Total field should be automatically updated to Quantity X Price, and also appear as R/O.
To implement this scenario, select the "Calculate Total = Price X Quantity" sample code:

We need to update the variables which appear at the beginning part of the script according to the column names we have in our list.
In our example, we have to change the following variable values:
var
priceFieldName =
"Price"
var
quantityFieldName =
"Quantity"
var
totalPriceWithTaxFieldName =
"Total"
var
taxFieldName =
""
(If you want also to display a Tax field, update the name of that field, otherwise replace
with
empty string)
The second script we should add is "Make the target fields appear read-only", which enables setting requested fields to be displayed as read-only fields. After you select that script, you need to update the following variable value to:
var
fieldsToDisable= [
"Total"
]
IMPORTANT: you need to use the internal column names, which might be different than their displayed names.
After you update the variable values in the script, save it and refresh the form. Now everytime you update the Price and Quantity fields, the Total field gets updated with the result of Price X Quantity, and also appears R/O: