Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › setFieldValue() and setFieldValues()
- This topic has 1 reply, 2 voices, and was last updated 3 years, 7 months ago by Daniel Leu.
-
AuthorPosts
-
April 18, 2021 at 2:47 AM #44197
Victor WarnerParticipantI have a simple requirement: for an existing record I wish to set certain fields with particular values (they are linked to pick lists).
According to the function lists I can use record.setFieldValue() or record.setFieldValues() but it is not working. Ideally I would like to use a Form script (and assign to shortcut key) as these default values only apply for some records but not others.
The script is as follows:
var name_id = 'fld-db21a48449d84ef4bfb6f4fb28473fa8'; var namex = record.getFieldValue('fld-db21a48449d84ef4bfb6f4fb28473fa8'); var deed_id = 'fld-9fe105d0c1a344b988899fafbb1f6e01'; var deed = record.getFieldValue('fld-9fe105d0c1a344b988899fafbb1f6e01'); var n_as_witness_id = 'fld-20109866d84b4587866be0cb63853547'; var n_as_witness = record.getFieldValue('fld-20109866d84b4587866be0cb63853547'); var number_of_witnesses_id = 'fld-7038bb074b3f42bca3ca6411c38ebe8b'; var number_of_witnesses = record.getFieldValue('fld-7038bb074b3f42bca3ca6411c38ebe8b'); var public_form_id = 'fld-e50974efdf284413abafd8aa9ebf36f1'; var public_form = record.getFieldValue('fld-e50974efdf284413abafd8aa9ebf36f1'); console.log(namex + " " + deed + " " + n_as_witness + " " + number_of_witnesses + " " + public_form); record.setFieldValue(namex,'James Smith'); record.setFieldValue(deed, 'Yes'); // record.setFieldValues({[deed]: 'Yes',[n_as_witness]: 'Yes', [number_of_witnesses]: '1', [public_form]: 'No'}); document.saveAllChanges
produces no errors but also does not set the fields to the defined values. I am sure there is something basic I am missing
Also is the syntax for record.setFieldValues correct?
The sample database is attached.
Help would be gratefully received.
Attachments:
You must be logged in to view attached files.April 18, 2021 at 9:44 AM #44199
Daniel LeuParticipantBoth
record.setFieldValue
andrecord.setFieldValues
require the field id as argument. That’s why your script doesn’t do anything since you provide a variable that doesn’t contain a valid ID.var name_id = 'fld-db21a48449d84ef4bfb6f4fb28473fa8'; var namex = record.getFieldValue('fld-db21a48449d84ef4bfb6f4fb28473fa8'); var deed_id = 'fld-9fe105d0c1a344b988899fafbb1f6e01'; var deed = record.getFieldValue('fld-9fe105d0c1a344b988899fafbb1f6e01'); var n_as_witness_id = 'fld-20109866d84b4587866be0cb63853547'; var n_as_witness = record.getFieldValue('fld-20109866d84b4587866be0cb63853547'); var number_of_witnesses_id = 'fld-7038bb074b3f42bca3ca6411c38ebe8b'; var number_of_witnesses = record.getFieldValue('fld-7038bb074b3f42bca3ca6411c38ebe8b'); var public_form_id = 'fld-e50974efdf284413abafd8aa9ebf36f1'; var public_form = record.getFieldValue('fld-e50974efdf284413abafd8aa9ebf36f1'); console.log(namex + " " + deed + " " + n_as_witness + " " + number_of_witnesses + " " + public_form); record.setFieldValues({[deed_id]: 'Yes',[n_as_witness_id]: 'Yes', [number_of_witnesses_id]: '1', [public_form_id]: 'No'}); document.saveAllChanges
I don’t really know what this script does since you are reading values and then overwriting them. But at least it stores the values now.
-
AuthorPosts
You must be logged in to reply to this topic.