Search Results for 'script'
Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Search › Search Results for 'script'
-
AuthorSearch Results
-
February 12, 2022 at 2:57 PM #46714
In reply to: Help with a script
Stig Widell
ParticipantYou wrote this earlier:
The Kalva function is there to create the calf, the first set of lines set up the various field ID’s we’re going to need later and then grabs the Avelstjur value for the current record. If that isn’t set we have an error message and return. It then looks for a match of that ID in the Avelstjurar form and if it doesn’t find it, also returns out. I did fix the type to match as number with the same formatting everywhere because I think initially it didn’t match properly due to a type mismatch (Javascript is a little more picky than TF).I cannot find that you are comparing the grupp field in form Aveltjurar with the grupp field in form Rekryteringsdjur? When these two match we have the correct Avelstjur and the father of the calf? That should be the crucial point.
So my question is: is there a search for match between the grupp fields in the two forms in the script Kalva??February 12, 2022 at 1:10 PM #46708In reply to: Help with a script
Stig Widell
ParticipantYou created the script Kalva to identify the field Avelstjur in form Rekryteringsdjur as I understood it??
February 12, 2022 at 1:05 PM #46707In reply to: Help with a script
Stig Widell
ParticipantBut the intention was not to use picklist at all but to let the script identify Avelstjur when grupp is the same in form Avelstjurar and form Rekryteringsdjur?
February 12, 2022 at 12:03 PM #46705In reply to: Help with a script
Stig Widell
ParticipantYes I know but why is the Avelstjur in form “Rekryteringsdjur” empty? The script should identify Avelstjur when field “grupp” is the same in records in form “Avelstjurar” and in form “Rekryteringsdjur”. When I insert a bull via picklist in form “Rekryteringsdjur” a calf record is created.
February 12, 2022 at 9:55 AM #46703In reply to: Help with a script
Sam Moffatt
ParticipantThe screenshot shows that Avelstjur is empty? It uses that field to determine the bull ID, with it empty then the script can’t find the bull to link to the child record.
February 12, 2022 at 1:27 AM #46702In reply to: Help with a script
Stig Widell
ParticipantOK Sam,
The font problem is fixed with Brendan´s help.
The script problem is still there.February 11, 2022 at 1:05 PM #46691In reply to: Help with a script
Sam Moffatt
ParticipantThat should only fire if Avelstjur is not set on the record you have selected in the Rekryteringsdjur form. If you’ve created a new field or are using a different field for the ID of the bull then you’ll need to update the field ID to match the new field ID on this line:
let keyValue = record.getFieldValue('fld-db52d7055ddd40cf95f50bcf8e2fff3d'); // ID of the Avelstjur field in Rekryteringsdjur form.The field ID is below the field description box which you can copy from there.
February 11, 2022 at 12:55 PM #46690In reply to: Pick list sort order (2nd)
Sam Moffatt
ParticipantI added this to my Script Manager so that if you want to set this up for a new script field it can look like this (once Script Manager is installed and update run):
document.getFormNamed("Script Manager").runScriptNamed("PicklistID"); PicklistID('fld-fa37906add2942c88bce3b500561c42d', 'Marketplace');One minor change was to fix an issue where the pick list was returned at the end if nothing was found and that now is returning a null that should show up as an empty value for the field (it was showing up was something like
[TFPicklist object]I think).February 11, 2022 at 12:32 PM #46689In reply to: Help with a script
Stig Widell
ParticipantSorry Sam but now when I run the Kalva script I am always stopped by this part:
// check if the bull is even set or error.
if (!keyValue) {
Utils.alertWithMessage(“Fel!”, “Avelstjur värde ej inställt!”);
return;
Whats the problem?February 11, 2022 at 10:01 AM #46686In reply to: Simple Prompter for adding via Siri
Sam Moffatt
ParticipantYeah, you need to return to Shortcuts after the execution. I only recently figured this one out, here is a quick snippet from one of my scripts:
if (parameters && parameters["x-success"]) { Utils.openUrl(parameters["x-success"] + "?message=Updated%20existing%20record&tfrec="+ targetRecord.getUrl()); } else { form.selectRecord(targetRecord); Utils.openUrl(targetRecord.getUrl()); } return "Updated existing record for " + clipboard;I also updated the shortcut so that it displayed the result text as a notification and then bounced me back to Tap Forms. I need to work on figuring out if I can update the UI before the bounce to have me land back on the record after the script completes.
Also attached a screenshot of the end of my Shortcuts that pairs with that script snippet.
Attachments:
You must be logged in to view attached files.February 11, 2022 at 6:00 AM #46683In reply to: Pick list sort order (2nd)
Mathieu Masseboeuf
ParticipantOh, indeed I didn’t noticed that answer !
(just tried with the ascii stuff, but I would have to refill everything, or script a replacement)Indeed, last time I checked TF didn’t had scripting, never used it … will have to check that out :P
February 10, 2022 at 11:29 PM #46679In reply to: Simple Prompter for adding via Siri
Prashant M
ParticipantHI Sam,
I’ve looked at the video you provided and I was able to call the script to work using ShortCuts .I did notice that the shortcut keeps working in the background & I need to manually stop it ,
is there a way to stop the same ?February 10, 2022 at 4:58 PM #46675In reply to: Total value of a table field
Sam Moffatt
ParticipantI have a set of forms I call the Script Manager that has a combination of various scripts that can be relatively easily downloaded and imported into Tap Forms for re-use.
February 10, 2022 at 2:17 PM #46674In reply to: Total value of a table field
Rob Naaijkens
ParticipantThank you Sam! I gonna take a look at it and hope I understand what I have to put where. Did you mean by the last sentence that you put this script into my export?
February 10, 2022 at 2:44 AM #46670In reply to: Total value of a table field
Sam Moffatt
ParticipantOk, so some changes. I ditched the table field and made it a new form and added a link to form field to connect it. In the new form, creatively labelled “Verkocht”, I added a form script (or three): Aggregate by Date, aggregateForm and md5sum. Attached is a copy of the template that should upgrade an existing document with the appropriate fields and scripts though let me know if it’s missing something.
Aggregate By Date is the script you’ll want to run to generate a report in “Nieuw formulier” grouped by date, name and the sum of aantal. If you look at it’s implementation, it looks like this:
form.runScriptNamed("aggregateForm"); function Aggregate_By_Date() { let fieldMap = { ['fld-cf72e8f115344d2fa33889757f9f19f0']: 'fld-28cad0a0ea4d4177aecd20e6f63fe470', // naam ['fld-ac527a6647d049869d5b3b26f8ef6d1d']: 'fld-4f2a8e2e7d974fc08f012a1889760397', // datum ['fld-ecae6c80bd38432abaaace22806dfb25']: 'fld-30f5df230f0b44479e53a83df9295e38', // aantal }; // set our date format, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString // remove "day" from it and you'll roll up by month for example. let dateFormat = { "day": "2-digit", "month": "2-digit", "year": "numeric"}; let translationMap = { ['fld-ac527a6647d049869d5b3b26f8ef6d1d']: (inputValue) => { return inputValue ? inputValue.toLocaleDateString("sv-SE", dateFormat) : ""; } } let targetForm = document.getFormNamed("Nieuw formulier"); return aggregateForm(form, targetForm, 'fld-ecae6c80bd38432abaaace22806dfb25', fieldMap, translationMap, {'logcsv':true, 'hashedrecord': true}); } Aggregate_By_Date();Ok, so we’re loading in the script “aggregateForm” at the start, that’s the utility/library file. Then we set up a field map, this maps the fields from the source form (in this case “Verkocht”) to the destination form (“Nieuw formulier”). Add extra to add more fields to the key/rollup or change up the ID’s to match.
We want to rollup by date so we nee dto format the date, that’s what this
dateFormatline does, specify the format for your date. Check out the docs to learn more but that’s pretty straight forward.The
translationMapbasically says to take the fieldfld-ac527a6647d049869d5b3b26f8ef6d1d(which should be a date) and turn it into a string representation of the date. If we don’t do this then we get big long date strings, not fun.Last lines say to get the
Nieuw formulierform and then run this aggregateForm thing. It takes a source form (which is the currentformselected; you could make this search too), it has a target form to create records in (or not if unset), the field ID of the field to aggregate, the two maps we talked about earlier and then the configuration options (logcsvcreates a CSV in your console log andhashedrecordmeans that it creates and updates the same record).The
aggregateFormscript looks like this:form.runScriptNamed("md5sum"); function aggregateForm(sourceForm, targetForm, aggregateField, fieldMap, transformerMap = {}, options = {}) { for (let defaultKey in defaults = { 'logcsv': false, 'hashedrecord': false, 'returncsv': false, 'returnjson': false, }) { options[defaultKey] = options[defaultKey] !== undefined ? options[defaultKey] : defaults[defaultKey]; } // check we have a source form, a field to aggregate and a mapping field. if (!sourceForm) { throw new ReferenceError("Unset source form"); } if (!aggregateField) { throw new ReferenceError("Unset aggregate field"); } if (!fieldMap) { throw new ReferenceError("Unset field map"); } if (fieldMap.length < 2) { throw new ReferenceError("Field map must have at least two entries (aggregate field and key)"); } let rollups = {}; let destField = fieldMap[aggregateField]; // iterate to all of the records in the form for (var rec of sourceForm.getRecords()) { //console.log(rec.getId()); let keyFields = []; let aggEntry = 0; let keyEntries = {}; for (let srcField in fieldMap) { //console.log(srcField + " => " + fieldMap[srcField]) let value = rec.getFieldValue(srcField); if (transformerMap[srcField]) { //console.log("Transforming..."); value = transformerMap[srcField](value, rec); } //console.log(value); if (srcField == aggregateField) { aggValue = value; } else { keyEntries[srcField] = value; keyFields.push(value); } } var rollupKey = keyFields.join(","); // Rollup to this key, add to the existing value or set it if not set. if (!rollups[rollupKey]) { rollups[rollupKey] = {}; for (let srcField in fieldMap) { rollups[rollupKey][fieldMap[srcField]] = keyEntries[srcField]; rollups[rollupKey][destField] = aggValue; } } else { rollups[rollupKey][destField] += aggValue; } } let retval = []; // log to console the aggregated values. for (let rollupKey in rollups) { if (options['logcsv']) { console.log(rollupKey + "," + rollups[rollupKey][destField]); } if (options['returncsv']) { retval.push(rollupKey + "," + rollups[rollupKey][destField]); } if (targetForm) { let destRecord; if (options['hashedrecord']) { let targetKey = "rec-" + md5(sourceForm.getId()+targetForm.getId()+rollupKey); destRecord = targetForm.getRecordWithId(targetKey); if (!destRecord) { destRecord = targetForm.addNewRecordWithId(targetKey); } } else { destRecord = targetForm.addNewRecord(); } destRecord.setFieldValues(rollups[rollupKey]); } } document.saveAllChanges(); if (options['returnjson']) { return JSON.stringify(Object.values(rollups)); } if (options['returncsv']) { return retval.join("\n"); } return rollups; }Nothing to customise there, it’s all parameterised. I’ll put it up in the script manager over the weekend.
Attachments:
You must be logged in to view attached files. -
AuthorSearch Results