Hi Daniel, Brendon,
This was actually just what I needed for my own database. Here’s the code I used to get it to work:
document.getFormNamed(‘Scripts’).runScriptNamed(‘prompterHelper’);
async function Selected_Items_Change_Follow_Up_Date() {
//Change Follow Up Date for Selected Items
let selected_id = ‘fld-ef53cc6a7a5f4ed2a51f7de0fa046400’;
let follow_up_date_id = ‘fld-6fa53ab54482495289f38b069d3c713f’;
try {
await textPrompter(‘Enter Follow Up Date (YYYY-MM-DD):’);
console.log(“User entered: ” + prompterVar);
} catch (errorText) {
console.log(‘User clicked cancel’);
return;
}
//let new_date = new Date(‘2023-07-03T00:00:00’);
let new_date = new Date(Date.parse(prompterVar + ‘T00:00:00’));
for(let baserecord of search.getRecords()) {
if (baserecord.getFieldValue(selected_id) === true) {
baserecord.setFieldValue(follow_up_date_id, new_date);
baserecord.setFieldValue(selected_id, false);
}
}
document.saveAllChanges();
}
Selected_Items_Change_Follow_Up_Date();
-
This reply was modified 2 years, 6 months ago by
Pinny Berlin.
-
This reply was modified 2 years, 6 months ago by
Pinny Berlin.
-
This reply was modified 2 years, 6 months ago by
Brendan.
I wondering the best way to prevent duplication of record names.
Rough Over view
I have these forms
Products
Formulations (many formulations records can link to many Products records)
Ingredients (many ingredients can link to many Formulations)
Each record has a name, How do I prevent duplication? Can you have the name field as you name it check no other record on the form contains the same record name?
IS this built in or does this need to be scripted?
any help would be appreciated.
-
This topic was modified 2 years, 7 months ago by
Greg Spink.
I’m sorry for that. Yes, it’s always important to make backups frequently. Sorry this happened to you.
I didn’t have your document and the script was just off the top of my head and wasn’t tested with your data.
That is cool.
How about a script to do that? Would be really appreciated.
The field script would be triggered by a change in the stepper field.
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
But, if I was able to build a script (which I can’t), could it be activated by the stepper or do I have to go into settings and select the script and run that? That would be more work that activating 2 steppers I would think?
You would need to use a Script Field to manage this. The Script Field would monitor the value of your stepper field and add to the value of the second field.
Brilliant!. Thank you it works…But the form doesn’t update. I have to close the database/document and reopen to see the results. I am executing the operation with form level script and I am using the “document.saveAllChange();” command but it doesn’t show results until I close and reopen.
Thoughts?
Thanks again!
The result is stored in the variable d. So you can take this and store the values in their respective fields.
record.setFieldValue(symbol_field_id, d["Global Quote"]["01. symbol"]);
...
document.saveAllChanges();
Most likely you want to create a new record where you save all these information so you can do some analysis over time.
The JavaScript API documentation is here: https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks
Hi Alan,
The Duplicate Document function just takes a copy of the document as is, copies it, and assigns it a new, unique Document ID. That’s all it does. So all field IDs, record IDs, form IDs, and so on will all be identical.
But a script should not make changes to a different document. It should still only operate on its own forms.
Can you check the Document IDs on each document to see if they are in fact different?
Thanks,
Brendan
Don’t know if I should have rewrote my original post. But looking at this further, I think “Duplicate Document” is referencing the same actual script object? When I make a change to the script in the duplicate document, those edits appear in the script in the original document.
Hi Brendan,
I used “Duplicate Document” from the “Database Documents” window to make a copy of a document for testing. When using the duplicate test document, I was confused when a script which changed field contents also changed contents of the field with the same name but in the original document I had made a copy of. I think what is going on is “Duplicate Document” made an exact copy of the script, which means the field IDs are the same in the original document and in the copied document. I am guessing that is why a script in the duplicated document is making changes to the original document. If this is the case, I am wondering if this is expected behavior. Thank you.
Ugh! Two seconds after posting this, I found the JavaScript API doc and it listed the function I needed – getFieldWithId().
Sorry to waste everyone’s time. But I’m happy I discovered the API doc, and hopefully I can use it to avoid asking questions like this in the future. :)
Thanks,
Pinny
Hello,
I am trying to reference a specific record in my form by its ID. I was able to obtain the ID via this script:
console.log(record.getId()); // returns ‘rec-6ca7e23ae2e44a2b94193cf0c8644ff6’
Now I want to reference that record in my other scripts. For instance, that record has a field called location. I was hoping to reference it using the following code, but I get an error:
aRecord = form.selectRecord("rec-6ca7e23ae2e44a2b94193cf0c8644ff6"); //record id of Current Location
location = aRecord.getFieldValue('fld-5dc7a719a9ee49b4b0536be6fdffeb46');
But it throws the error:
TypeError: Argument does not match
Objective-C Class, line:(null)
I’m sure there’s a simple way to accomplish what I need (short of looping through each form record and checking the Id. Any help is appreciated!
Thanks,
Pinny
On the iPhone, you can have Shortcuts as well. They use the shortcut app and work together with Siri. You can launch a scripts using them. I never used this as I barely us TF on my phone. Sam has a video where he shows how he uses Shortcuts. I hope this helps you get started: https://www.youtube.com/watch?v=B7oiWtRRuNY&t=559s&ab_channel=pasamio
Cheers, Daniel
---
See https://lab.danielleu.com/tapformspro/ for scripts and tips&tricks