Daniel, Brendan,
Thank you for the replies. I must be missing something very fundamental as I do not seem to be able to be apply your replies.
For Brendan’s post:
var dupes_search = form.getSearchNamed('For duplication');
var records = dupes_search.getRecords();
Do I put this is in a form script? Is any other code needed so that what is returned are just the records which match the ‘For duplication’ saved search?
Having entered those two lines into a Form Script, nothing is returned.
One way I do something like this is to use a Link to Field JOIN field with a common key between the grandparent record and the child record. You might be able to use a calculation field to project down a key value though for my use case I already had one that I was replicating via scripting.
If all you want is all of the grand children listed in the grandparents record (which is very useful at times) then the JOIN field might be the answer to do it somewhat automatically.
If that isn’t what you had in mind then you’re going to be doing some scripting however you can use the calc field if the JOIN field idea works.
Thanks Brendan,
This helps me understand the picklist programming. I’ll play around with it.
Unfortunately it needs a document close/open. I really need an ability to have a dynamic picklist on a record by record basis.
BTW I have really enjoyed the increase in power with scripting in Tap Forms. My favorite app.
Hi Brendan,
yes, that is what I need.
Do you have an idea, how that script looks like?
I am trying to understand how to use the scripting commands to automate some searches, but not able to understand from the available documentation how to use them.
Example:
1. I have a form called Time spent, one of the fields is called ‘For duplication’. For some records the only entry is a “X”
2. I have created a saved search called “For duplication” which only function is search records in the ‘For duplication’ field which contains an “X”
Queries
1. Is it possible to create a form script which uses the saved search called “For duplication”
2. Also how would I create a search with a script to search a field for a value (such as search the “For duplication” field for a “X”.
Any help gratefully received.
Hi Gerhard,
Do you mean you have a 3 level hierarchy and you want to show data from the lowest level to the top level?
Like Parent -> Child -> Grand Child and you want to show data from Grand Child on the Parent form?
You can do that with a script, but the way the data would be displayed would be just in a text format, not in something like a table like regular Link to Forms are displayed.
Hi Johnny,
Sorry for my delayed response.
Improving the JavaScript API to support more Pick List functions such as pickList.addValue('Sci Fi') or pickList.addValues(some_values_array); is on my toDo list.
But I haven’t worked on that yet. In the meantime, something like this will work, but it does seem like you still have to close the document and re-open it for the new values to appear:
function AddToPickList() {
var pick_list = document.getPickListNamed('Condition');
var pick_list_values = pick_list.values;
// print the current set of values. You can see the dictionary format you need. You can optionally provide a <code>valueColour</code> (yes, Canadian spelling) property key too. Use the colour format you see.
console.log(JSON.stringify(pick_list_values));
var new_value = {"value" : "My New Pick List Value"};
// add the new value to the values array.
pick_list_values.push(new_value);
// reset the list of values with the array that contains the new value
pick_list.values = pick_list_values;
// saving on the pick_list
pick_list.saveChangesInDatabase();
// log our new set of values.
console.log(JSON.stringify(pick_list_values));
}
AddToPickList();
In a future update I’ll add a better API for Pick Lists. I’ve tested this and it does work.
Hello together,
is there a way, to combine more than two linked forms with “m to n” or “1 to n” relation?
The following task: Main form: Company
Goal: Project tracking with an “m to n” link. I would like to create a project tracking, there I need the users-name, for every project the cal-dates, notes, different pick lists and other things. Then I need to show the results in the higher-level Company form. However, I cannot do this with the previous tools from TabForms. Can something like this be realized with a script?
Best regards,
Gerhard
I know there are some methods exposed to the pick list object. I have not got any success using it. I have the iOS version of Tap Forms 5.
I am working on a movie database. I have a need to have a pick list of all actors that are in the current record movie.
I have written a script that gets the actors from an online service. It deletes all rows from a hidden actor form, then populated the form with actors from the movie which is the current record.
The actors Pick List gets it’s values from the Actors Form. The problem is the Pick List seems to only populate with the updated values on document load.
Is there any way of triggering a Pick List to populate progamically? This would solve my problem.
Or am I going about this all wrong?
If there was a way to alter the dictionary object associated with Pick List that would work too. However I have not been able to get a Pick List object to return a dictionary, all I get is an undefined object. I know I am doing something wrong. An example of using the Pick List object and methods would be great.
As @cattailnu said, it’s a short hand conditional known as a ternery operator. I feel it makes things a little more concise instead of having to fit in an if/then/else clause, we can collapse it down to a single line.
If you look at the MDN link the use case we’re referring to is the “handling null values” one where if the variable is undefined (the error you reported), we use the alternate value. If it’s a “truthy” value (basically anything not falsy, aka false, 0, 0.0, an empty string like "", null, NaN or undefined), then we use the same value.
So the reason why it’s repeated is because if the value is truthy, we want to use it but if it is falsy we want to return the 0.0 value as a fallback. There might be some data that this breaks on but so long as it’s an actual number it should do what you need.
It’s saying the value of the variable is undefined and not a valid value. A quick trick would be to rewrite to insert an empty value:
form.runScriptNamed(‘sprintf’);
var s_total_for_invoice = sprintf(“%0.2f”,total_for_invoice ? total_for_invoice : 0.0);
var s_payment_amount = sprintf(“%0.2f”,payment_amount ? payment_amount : 0.0);
console.log(s_total_for_invoice + ” ” + s_payment_amount ? s_payment_amount : 0.0);
It should capture the undefined and turn it into a zero value. That should at least cause the script not to fail.
Looks like I missed @cattailnu’s post, I don’t know why globalThis wouldn’t be defined, it seems to work for me and it should exist as it’s supposed to be a JSC provided variable so it not being set seems odd.
Based on the above, I entered the form script as Sam managed and then in the script where I wish to use sprint I added the following code:
form.runScriptNamed(‘sprintf’);
var s_total_for_invoice = sprintf(“%0.2f”,total_for_invoice);
var s_payment_amount = sprintf(“%0.2f”,payment_amount);
console.log(s_total_for_invoice + ” ” + s_payment_amount);
The field total_for_invoice is a calculation field and payment_amount is a number field.
The first record I ran the script (recalculate formulas) it worked, the second and subsequent times I am getting the following error:
Wording for invoice: TypeError: [sprintf] expecting number but found undefined, line:(null)
However, occasionally it does work and then a further run it will stop working.
Using the example database that T.L. Ford provided has not resulted in the error at all.
Any help would be gratefully received.
Sometimes you can use Google to search the site (e.g. https://www.google.com/search?client=safari&rls=en&q=site:www.tapforms.com/forums+number+formatting&ie=UTF-8&oe=UTF-8) to find stuff.
If you have a simple return value in your script field (e.g. you return 150 or 150.5) if you set the format of the field to number, you can use the Tap Forms field formatting options to change the number of decimal places to be two.
If you need to format in Javascript, I made a port of a Javascript sprintf implementation as a part of the Script Manager stuff or you can directly grab it from GitHub. This adds an sprintf function you can use to format numbers in Javascript as a part of a larger string formatter.
For Brendan,
I have asked this question before and have received an answers, but until now not needed it. However I can see I have asked 49 questions but cannot access any posting beyond the first page. It is likely the answer is on one of the pages I cannot access.
Now the question…
Question
In some of the scripts I have created there are figures / sums taken from fields.
But I would like to format them correctly. For example:
1. if the amount is 150.00 it appears in the script is run as 150
2. if the amount is 150.50 it appears in the script as 150.5
etc.
How is it possible to format numbers so that there are always two decimal places?
Hi,
I’ve been trying to write a java script for some time without success, because my skills are limited (i’m still learning ;-)).
The
My path / goal can be described as follows:
1. A record (“current_record”) is currently selected in form “AR”. A new record (“new_record”) should be created in the form “AR”.
2. The new record (“new_record”) should contain all (or selected) linked form (“AR-Posten”) records (“linkedform_records_of_current_record”) of the currently selected record (“current_record”).
3. AND: Data from only CERTAIN fields should be taken from the linked form records (“linkedform_records_of_current_record”) and filled in the fields of the new child records.
My code (only an exerpt) looks like this:
// linked form AR-Posten id
var ar_posten_id = ‘fld-265897a72a6f467c9185cfeae6c31d57’;
var ar_posten = record.getFieldValue(ar_posten_id);
// field ids from linked form records "AR-Posten", only two for example
var p_id = 'fld-59deac8c932245ca81925170193f62f3';
var quote_id = 'fld-c00267497ef94d70b6778329cff05d0b';
// add new record to AR
var new_ar = form.addNewRecord();
for (var index = 0, count = ar_posten.length; index < count; index++){
var p = ar_posten[index].getFieldValue(p_id);
var quote = ar_posten[index].getFieldValue(quote_id);
...
My question is:
How can i add/link new child records (“AR-Posten”) to the new record (“AR”) and fill each with the field data from “child_records_of_current_record”.
Actually there is no function in the java script API with which one can duplicate records and at the same time all linked child form records. The fields (ids) for the current record and the linked form records (only for the first stage) to be duplicated should be determined in the function.
I hope my explanation is understandable.
Thanks in advance
Chris