Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Help with a script with two conditions
- This topic has 14 replies, 3 voices, and was last updated 11 months, 4 weeks ago by Fernando DS.
-
AuthorPosts
-
November 21, 2023 at 7:55 AM #50150
Fernando DSParticipantHi. I want to do an script for autocomplete a note field called “Comentario” with “Buen disco.”, when the valoration field “Valoración” has four stars and, at once, the field “Comentario” is empty. I have not errors in the console, but the script does not work. Any help will be welcome. Thank you.
Attachments:
You must be logged in to view attached files.November 21, 2023 at 10:53 AM #50152
BrendanKeymasterHi Fernando,
try
==
instead of===
. But it could also be that you just need to check for4
instead of"4"
because the Rating field returns a number, not a string and you’re checking to see if the value is the string"4"
and not the number4
.November 21, 2023 at 11:25 AM #50153
Fernando DSParticipantHi Brendan, thank you for your answer. The script is steel not working.
Attachments:
You must be logged in to view attached files.November 21, 2023 at 3:48 PM #50155
Daniel LeuParticipantThere’s a second “===” instead of a “==”.
November 21, 2023 at 9:35 PM #50156
Fernando DSParticipantIt’s true. I have corrected it, but the result is the same.
Attachments:
You must be logged in to view attached files.November 22, 2023 at 12:07 AM #50158
Daniel LeuParticipantIt would be easier if you posted your code here instead of the screen capture. But I think that the
form.saveAllChanges()
should be before the closing bracket above.November 22, 2023 at 12:38 AM #50159
Fernando DSParticipantSorry for my ignorance, but how do I send the code?
November 22, 2023 at 5:13 AM #50160
Fernando DSParticipantWell, I’m going to paste it here.
function modifyFieldsBasedOnCondition() { var fieldId1 = 'fld-28b97ce8ab4f4f57a83aefa7e91f17fe'; var fieldId2 = 'fld-c2fd26ae62c1445692b3a0abc1e89158'; for (var record of form.getRecords()) { if (record.getFieldValue(fieldId1) == 4 && record.getFieldValue(fieldId2) == "") { record.setFieldValue(fieldId2, "Buen disco."); } } form.saveAllChanges(); } modifyFieldsBasedOnCondition();
- This reply was modified 11 months, 4 weeks ago by Brendan.
November 22, 2023 at 6:30 AM #50161
Fernando DSParticipantHope this is what you said Daniel.
November 22, 2023 at 10:19 AM #50163
BrendanKeymasterHi Fernando,
What type of field is
fieldId2
? Is it a Text field or a Number field? Because you’re comparing it to the empty string""
.You might want to check to see if it’s
undefined
November 22, 2023 at 10:58 AM #50165
Fernando DSParticipantIt’s a note field. I write my opinions about discs in it and I need enough extension.
November 22, 2023 at 11:33 AM #50166
Fernando DSParticipantSo it’s a field of text, not numbers.
November 22, 2023 at 2:22 PM #50167
Fernando DSParticipantJust another try, without errors in console, but not works.
function modifyFieldsBasedOnCondition() { var fieldId1 = 'fld-28b97ce8ab4f4f57a83aefa7e91f17fe'; var fieldId2 = 'fld-c2fd26ae62c1445692b3a0abc1e89158'; for (var record of form.getRecords()) { if (record.getFieldValue(fieldId1) == 4 && record.getFieldValue(fieldId2) <= (0)) record.setFieldValue(fieldId2, "Buen disco."); } } form.saveAllChanges(); modifyFieldsBasedOnCondition();
- This reply was modified 11 months, 4 weeks ago by Brendan.
November 22, 2023 at 5:11 PM #50169
Daniel LeuParticipantThis works for me:
function modifyFieldsBasedOnCondition() {
var fieldId1 = 'fld-28b97ce8ab4f4f57a83aefa7e91f17fe';var fieldId2 = 'fld-c2fd26ae62c1445692b3a0abc1e89158';for (var record of form.getRecords()) {console.log(record.getFieldValue(fieldId1));console.log(record.getFieldValue(fieldId2));if (record.getFieldValue(fieldId1) == 4 &&record.getFieldValue(fieldId2) == undefined){record.setFieldValue(fieldId2, "Buen disco.");console.log("empty record found");}}form.saveAllChanges();}modifyFieldsBasedOnCondition();- This reply was modified 11 months, 4 weeks ago by Daniel Leu.
- This reply was modified 11 months, 4 weeks ago by Daniel Leu.
- This reply was modified 11 months, 4 weeks ago by Daniel Leu.
- This reply was modified 11 months, 4 weeks ago by Daniel Leu.
- This reply was modified 11 months, 4 weeks ago by Daniel Leu.
November 22, 2023 at 11:29 PM #50176
Fernando DSParticipantAt last this is the script that works:
function modifyFieldsBasedOnCondition() {
var fieldId1 = ‘fld-28b97ce8ab4f4f57a83aefa7e91f17fe’;
var fieldId2 = ‘fld-c2fd26ae62c1445692b3a0abc1e89158’;for (var record of form.getRecords()) {
var valueField1 = record.getFieldValue(fieldId1);
var valueField2 = record.getFieldValue(fieldId2);if (valueField1 === 4 && (valueField2 === null || valueField2 === “”)) {
record.setFieldValue(fieldId2, “Buen disco.”);
console.log(“Campo fieldid2 actualizado en el registro con campo fieldid1 igual a 4 y fieldid2 vacío.”);
}
}form.saveAllChanges();
}modifyFieldsBasedOnCondition();
Thank you Brendan and Daniel for your valuable help.
Bye.
-
AuthorPosts
You must be logged in to reply to this topic.