Jump to content

Please chech this script before I use it.


This topic is 6100 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi Guys,

The following is the message I first posted on the Café. The response I received is shown as “ErrorScript” and the person said [color:red]“I am sure others will chime in on this, but here is my fellow novice opinion.” No one else chimed in so I don’t know if that means, this is the way to go or not. I just thought if you guys took a look I at least have a confirmation.

My Question: There are five fields that the customer must enter information to continue. If they have not entered into all 5 fields, they get a message saying they cannot continue until the fields are entered and each of the non-entered fields are listed. I need this message to be in a field, not a dialog box.

The Answer: ErrorScript:

If[Customers::City ≠ "" and Customers::State ≠ "" and Customers::Zip ≠""]

Set Variable [$CustomerID; Value:Customers::CustomerID]

Go to Layout ["Invoice" (Invoice Table)]

New Record/Request

Set Field [invoice::CustomerID; $CustomerID]

Else

Set Field [Customers::ErrorField;

"Please Complete the Following Fields: "&

Let ( [Test1 = If (Customers::City = ""; "City"; "");

Test2 = If (Customers::State = ""; "State"; "");

Test3 = If (Customers::Zip = ""; "Zip"; "")];

Test1 &

Case (Test1="" and Test2 ≠ ""; Test2;

Test1 ≠ "" and Test2 ≠ ""; ", "&Test2;

Test1 ≠ "" and Test2 = ""; "") &

Case (Test1 = "" and Test2 = "" and Test3 = "";", " & Test3;

Test1 = "" and Test2 ="" and Test3 ≠ ""; Test3;

(Test1 ≠ "" or Test2 ≠ "") and Test3 ≠ ""; ", " & Test3;

Test3=""; ""))

End If

The above works and I now need to know how to add 13 more fields. The If statement is clear and I added the fields with no problem. But the Set Field after the Else statement is a whole other story.

My main question is, is the above a good way to handle this?

Thank you very much,

Milo

Link to comment
Share on other sites

Customers::City ≠ ""

Not the best way to check if a field is empty. Instead, use the IsEmpty() function.

Before checking for field data I usually strip out leading and trailing white space (spaces, paragraphs). The Trim4 custom function is ideal for this. It's on Brian Dunning's site.

IsEmpty( Trim4( fieldname ) )

To check if a field is NOT empty use

not IsEmpty( Trim4( fieldname ) )

Link to comment
Share on other sites

Hi Vaughan,

Maybe you could help me with one more thing. I’ve been trying to figure out how to add to the Set Field after the Else statement. I have fields I need to add and I cannot figure out how to do it.

The If statement was easy enough to figure out but I can’t understand all of the “Test and Case”. Could you show me how to add another field? I have another 13 fields to add and absolutely no idea how to do it.

Thank you,

Milo

Link to comment
Share on other sites

I'm not sure it's the best way, wouldn't it be better only to regard the fields actually present on a layout, no matter how many it holds?

The script as it is in the attached template needs to be broken out in subscripts, but the only way to get what it's about is to trace it via the second from left button in the debugger, due the numerous recusions, but recusions are chosen for it's stacking of paramters, instead of making a long string of parameters delimited via say ¶...

--sd

igotit.zip

Link to comment
Share on other sites

Hi Soren,

Hey thanks for the file. It sure helps to be able to see what to do in real time. This is a solution that will be on the web so I can't use a pop up message; it has to be in a field. How would you change the scripts so the message is shown in a field and separated by a carriage return?

Milo

Link to comment
Share on other sites

If you take a look - I kind of knew you might be IWP'ing, hence the gathering of the message in an invisible global field before flashing it, you could have it in a different invisible tab, as log as it's pulled out of the cursors taborder:

http://www.databasepros.com/FMPro?-DB=resources.fp5&-lay=cgi&-format=list.html&-FIND=+&resource_id=DBPros000816

...although it isn't a differnt sortorder of the same data here, is it the same tecnique to make the tabs invisible.

--sd

Link to comment
Share on other sites

Hi Soren,

I Read and reread and then rereread your post. I opened the file, scratched my head, closed the file, ran some ice cold water over my face, reopened the file again, read the information, looked at what was happening, went back to the kitchen, added some Scotch to that cold water and realized anew how much fun you FileMaker guys can really be!

I even went back over my posts thinking "Hey maybe I said something to make Soren think I had a clue. But I realized very quickly that wasn’t it. So it could only come down to one thing. That Ol Soren is really having fun with Ol Milo.

Now if you're through gloating over having a good time at the expense of the Wyoming Boy, what should I really do?

Milo

Link to comment
Share on other sites

It seems to me the "Test & Case" portion is just trying to construct a semicolon separated list of the empty field's display names.

Here's an example file showing an alternative way using a custom function to build up a list of empty field's name's.

The important part is the custom function:

EmptyFields( fieldNmes; accum ) =


If ( IsEmpty(fieldNmes); accum;

  Let( [ firstFieldName = GetValue(fieldNmes;1);

           restNames = RightValues( fieldNmes; ValueCount(fieldNmes) - 1 );

           fieldIsEmpty = not IsEmpty(firstFieldName) and IsEmpty(GetField(firstFieldName))

         ];



         EmptyFields( restNames; accum & 

                If ( fieldIsEmpty; If (not IsEmpty(accum); ¶) & firstFieldName) )

       )

)

testNCase.fp7.zip

Link to comment
Share on other sites

Cool, but in order to get almost total independence in deployment which was my objective - could this be used instead of the hardwired:

Let(tt=FieldNames ( Get ( FileName ) ; Get ( LayoutName ) );Substitute ( tt ; ["¶message" ; "¶"];["¶¶";"¶"] ))

...leaving the fieldname "message" a reserved word, which can't be part of any of the other fieldnames.

--sd

Link to comment
Share on other sites

I saw it Michael, and turned the calc' unstored ...it seems to work. But it favours perhaps the scripted method then?? My agenda is to an as portable algorithm as posible!

what should I really do?

If IWP'ing is the main thing here, would I ditch the "reporting" or "messageing" and instead provide the interface itself with some signaling! Take a look! (good grief I'm flagging - hardly an embraced scripting style!)

The scripting might seem a little clunky, but:

http://www.filemaker.com/help/Script-Steps36.html

isn't web-compatible!!!

--sd

HowIwouldIWP.zip

Link to comment
Share on other sites

Hi Guys,

Of everything I've seen it looks like the "HowIwouldIWP.fp7" solution is the easiest to implement and I really like that the error is shown in the actual field instead of a list of fields.

I added a new field and boom, it was right there included in the list. My question is, what if you have a field or two on the layout that is not a "Must Enter" field. How do you exclude these fields from the search?

One other thing I just noticed and that is we need to keep them from going to the next layout until all required fields are filled in.

You guys are great by the way.

Milo

Edited by Guest
Link to comment
Share on other sites

Hello again,

Comment, I don’t think date and time fields would come into play on this layout so that should not be a problem

Soren Said: Fire the script in another layout where the fields are excluded and then turn back to the layout you wish the user to see!

I don’t follow. We’re on the Customer Setup layout that has 10 must enter fields and 3 optional fields. I don’t understand how going back and forth to anther layout would handle the "Must enter fields from the Optional fields and wouldn't that be very confusing to the customer?

Or are you talking about "going to the next layout after all required fields are filled in"?

Milo

Link to comment
Share on other sites

This is so COOL I can hardly stand it. Where do you guys come up with this stuff?

I just need your help on two things. When a Must Enter field is missed and you get the [color:red]......................, when you enter infromation it stays [color:red]RED. How do I get it back to Black?

The other thing is once everything is entered correctly, how do I get to the next layout called "Business Page"?

Milo

Link to comment
Share on other sites

I saw it comming and began the next template with conditional formatting, however can something be done! You could prepend the asterix'es with ... in the default font and then followed by the colored ones.

But please explore the "condtional formatting" it seems a more obvious path!!

--sd

Link to comment
Share on other sites

Hi Soren,

What I did is just changed the ******* from red to Black and that solved the whole problem. Not as elegant as the red, but it works.

One last question. I have the following script that I would like to add to your Mandatory script. How do I add it so it triggers only after the other conditions are met?

Set Variable [ $id; Value:Customers::ContactID ]

#Go to the invoice layout

Go to Layout [ “Customer Entry” (Invoices) ]

#Make the invoice

New Record/Request

#Push the contact ID from the variable

Set Field [ Invoices::ContactId; $id ]

#

Commit Records/Requests

[ Skip data entry validation; No dialog ]

Thanks Soren,

Milo

Link to comment
Share on other sites

I was going to suggest that your button simply set a field to 1 to toggle the formatting on and off; the fields would all have the conditional formatting formula:

IsEmpty(Self) and testNCase::evaluated = 1

This works great to set the fill color of the empty fields.

Unfortunately conditional formatting doesn't work in IWP. ;)

Link to comment
Share on other sites

  • 2 weeks later...

Hi Soren,

If you look at post #269382 it shows a “Make Invoice” script that captures an ID# from the Customer TO and takes that same ID# and creates a new invoice in the Invoice TO. This script works perfectly if you run it by itself from the Customer TO.

Here’s the problem. This script is called from within another script shown on post #269546 showing where the above script was placed. That’s where I put it and it does go to the right layout in the Invoice TO but it does not make a new record.

What do I have to do to get the script to work correctly.

Milo

Link to comment
Share on other sites

This must be a layout wich reside in a different TOG where the setting of:

Set Variable [ $id; Value:Customers::ContactI D ] 

..not quite makes sence, what does the Dataviewer tell you when you trace it with the debugger?

Another thing it could be is if you have several files in your solution, variables does only live until the boundaries of each file it's defined in, to solve this use script-parameters/result instead!

--sd

Link to comment
Share on other sites

Hi Soren,

Another thing it could be is if you have several files in your solution, variables does only live until the boundaries of each file it's defined in, to solve this use script-parameters/result instead!

I'm not exactly sure what you mean. Could you show me based on the script shown on post #269546 above?

Milo

Link to comment
Share on other sites

No! Really - I need to see the file(s) before making a proper judgement ... it should be straight forward but what you unintended have kept out of the equation - is pretty hard to guess!

However do you in the thread:

http://fmforums.com/forum/showtopic.php?tid/190966/post/271080/#271080

...talk about the separation model, which means several files in plural ... this is an obvious limitation of the $variables scope!

--sd

Link to comment
Share on other sites

Hi Soren,

As I said earlier, if I run the “Make Invoice” by itself it works perfectly. It just does not work when added to this script. It looks from what you’ve said that the problem may be in the “$variables”. Is there another way to do it by replacing the “$variables” with something else?

Milo

Link to comment
Share on other sites

Variables arrived with fm8 or fm8.5 before that were other means chosen, script-paramters arrived with fm7 ... before that was yikes! global fields used.

But couldn't you let us poke into your stuff to establish the reason why the variable doesn't work? Why do you use a $variable and how does it get it's value, well the script kind of say it, but what we can't see is if you attepts to transfere it's value to a new file.

--sd

Link to comment
Share on other sites

"As I said earlier, if I run the “Make Invoice” by itself it works perfectly. It just does not work when added to this script. It looks from what you’ve said that the problem may be in the “$variables”. Is there another way to do it by replacing the “$variables” with something else?"

Normal $variables only work within the script in which they are created. This could be the problem.

To pass values between scripts in the same file, use global $$variables.

To pass values between scripts in different files, use either script parameters or store the values in global field and access them via a relationship.

Link to comment
Share on other sites

This topic is 6100 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.