Hi Victor,
So what you’re looking for then is user interface automation? That is a form script that clicks on the “For duplication” saved search for you?
If so, then a script won’t do that. Right now the only user interface automation a script allows you to do is to select a specific record.
I’m just curious what the purpose of that would be though? To save a click? Or is there a larger form of automation you’re looking to integrate this into?
Thanks,
Brendan
Sam,
Thank you for the detailed reply.
I can see that script duplicates the fields which have an X in the For duplication field.
I am sorry to be difficult, but this is not what I would like to achieve.
When I click on the ‘For duplication’ saved search under the relevant Form in the Forms list what happens is, in effect, Tap Forms shows (filters) only and displays the records for which in the For duplication there is a X.
That is all I am trying to achieve with a script (if possible). Tap Forms has no way of ‘reaching’ a saved search via the menu, a shortcut or pressing the tab key successively that I am aware of. There are other parts of Tap Forms which are also not reachable, but I have been able to get to them through the use of UI Browser, but even this is having difficulty with saved searches.
If of assistance, the example database I am using is attached.
Attachments:
You must be
logged in to view attached files.
Something like this should do the trick as a form script:
var dupes_search = form.getSearchNamed('For duplication');
for(var baseRecord of dupes_search.getRecords()) {
baseRecord.setFieldValue('fld-dupeflag', false);
var dupeRecord = baseRecord.duplicate();
}
document.saveAllChanges();
First line gets the named search, the next line loops over all of the records in the search, the setFieldValue unsets your dupe flag field. The var dupeRecord line duplicates the baseRecord and hands you a copy of the record with the ever present document.saveAllChanges() to flag you want to save things.
You might want to swap the baseRecord.setFieldValue line to be after the duplicate() call and apply it to only the duplicated record (e.g. dupeRecord.setFieldValue('fld-dupeflag', false)) however I’m not entirely sure.
Haven’t tested this but I think this should do roughly what you need. It’ll take anything that matches the saved search ‘For duplication’, duplicate them for you and clear the dupe flag (useful if you don’t want to dupe them again).
Daniel,
Thank you for the reply.
What I would like to do is simply create the equivalent of selecting by clicking on the saved search “For duplication” under the relevant Form in the Forms list, so that the only the records for the field called For duplication that contain a X appear.
Unless there is an option I have not discovered, saved searches are not selectable via a menu (or a shortcut key). A form script can have a shortcut assigned to it.
Is what I wish to do achievable with a form script?
To be clear what I am trying to create the equivalent of, attached is a video.
Attachments:
You must be
logged in to view attached files.
With these two lines you get an array of records for your named search stored in a variable. Then you have to do something with them. What do you want the script to do?
A form script is used to perform an action such as to modify a record. A field script returns a value that is stored in the script field. So they serve a different purpose.
Brendan, good catch! Thanks!
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
The object model can be used to walk all over the database from anywhere to everywhere using the IDs and a good understanding of the model.
http://www.cattail.nu/tap_forms/tap_forms_scripting_102/index_object_model.html
Link to Form fields do not show up in the interface’s available fields for Linked forms, but you can still use them.
Example:
i.e.
Projects (project name) -> Project_Employees (allocated manhours) <- Employees (employee name)
Show:
Project, Employee Name, Allocated Hours
In a Projects form script, you can easily get the list of allocated manhours from the linked field. However, you need to also get the linked field for Employees from the Project_Employees table for the Employee name.
Even though it doesn’t show up in the interface’s picklist, you can still use them. You just have to go get the IDs from the Linked form.
See the attached database, which shows this in action as well as how to build a Summary report from partial reports.
Attachments:
You must be
logged in to view attached files.
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