Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Clearing Global Fields


cschmitz

Recommended Posts

I have a script that uses a loop to grab values from repeating fields. The loop is structured roughly like this:

=============

set variable [$$ct; Value: 1]

Loop

if(IsEmpty(Quantity [$$ct] = 0)

set field [externalDB::gQuantityTemp[$$ct]; Quantity[$$ct]

end if

if(IsEmpty(PartNum [$$ct] = 0)

set field [externalDB::gPartNumTemp[$$ct]; PartNum[$$ct]

end if

if(IsEmpty(Cost [$$ct] = 0)

set field [externalDB::gCostTemp[$$ct]; Cost[$$ct]

end if

Set Variable [$$ct; Value: $$ct+1]

Exit Loop If [$$ct = 40]

End Loop

=============

The loop works fine. My question is about clearing out the global fields. I don't want any values in any of the global fields when the loop starts.

 

Currently I create a second loop that is goes through the same way and sets all of the field repititions to "" after the task is done, but its a lot of extra lines in the script. Tt seems like there should be an easier way of just saying 'Clear all global fields', but I don't know what it is. Is there a feature like this??

Link to comment
Share on other sites

if(IsEmpty(Quantity [$$ct] = 0)

Repeating fields? Don't do it. Use a related table instead.

 

IsEmpty ( field = 0 ) will always return boolean false regardless of the field contents so you might as well use If ( 0 ) for what it's worth. I think you need to revisit your logic. If(IsEmpty(Quantity[$$ct]) or If(Quantity[$$ct] = 0) are valid options.

Link to comment
Share on other sites

Sorry, I phrased my question wrong.

 

My company has: database with repeating fields

I have: no choice

 

Really I wrote a brief description of the loop just to give an idea of how I get the values into the global fields. My question was asking if there is an easier way to clear out global fields in this situation aside from creating an additional loop that clears out the values.

 

As for the logic being wrong, that was a typo on my part. It should have read: if(IsEmpty(Quantity [$$ct]) = 0) I missed a closed parentheses when typing it into the post. Filemaker won't even let you put if(IsEmpty(Quantity [$$ct] = 0) into the if statement b/c of the syntax error.

Link to comment
Share on other sites

I think the only alternative to your loop is to import a record with a corresponding repeating field that's blanked out. You'd have to use the matching option in the Import dialog (and have the recordID populated in the source record).

 

But I think the loop would be the safer way to go.

Link to comment
Share on other sites

set variable [$$ct; Value: 1]

Loop

if(IsEmpty(Quantity [$$ct] = 0)

set field [externalDB::gQuantityTemp[$$ct]; Quantity[$$ct]

end if

if(IsEmpty(PartNum [$$ct] = 0)

set field [externalDB::gPartNumTemp[$$ct]; PartNum[$$ct]

end if

if(IsEmpty(Cost [$$ct] = 0)

set field [externalDB::gCostTemp[$$ct]; Cost[$$ct]

end if

Set Variable [$$ct; Value: $$ct+1]

Exit Loop If [$$ct = 40]

End Loop

=============

The loop works fine. My question is about clearing out the global fields. I don't want any values in any of the global fields when the loop starts.

 

Currently I create a second loop that is goes through the same way and sets all of the field repititions to "" after the task is done, but its a lot of extra lines in the script. Tt seems like there should be an easier way of just saying 'Clear all global fields', but I don't know what it is. Is there a feature like this??

 

I have to say that the logic looks fractured.Why not just replace all the field values with zero:

 

if(IsEmpty(PartNum [$$ct] = 0)

set field [externalDB::gPartNumTemp[$$ct]; 0 )

end if

 

Refined:

Sample to set values to zero per last question. Change actual fields...

 

set variable [$$ct; Value: 1]

Loop

set field [externalDB::gQuantityTemp[$$ct]; 0 )

set field [externalDB::gPartNumTemp[$$ct]; 0 )

set field [externalDB::gCostTemp[$$ct]; 0 )

Set Variable [$$ct; Value: 0 )

Exit Loop If [$$ct = 40]

End Loop

 

There's nothing wrong with repeating fields if they are used properly. Here you are creating an array and arrays are quite popular in other high end databases.

 

However, related records are far more functional but to avoid an array in its simplicity is a crime. Disregard the comments made against related fields. Just use them when they work properly.

Link to comment
Share on other sites

Jack, sorry the logic was fractured b/c I forgot a close parentheses in the original posting (see my second post on this thread). Basically what the loop does is say 'if there is a value in the given field, copy that field's contents into a global field in an external database'.

 

The way it was originally written it looks like I'm trying to set values to 0 if they're 0. That was my misstype.

 

I do think it would be best to use a related table, and in the new system that I am building for the company it will use a related table. It's just until I can finish and fully implement my system I need to patch together what is already there, which is why I'm messing with the repeating fields.

 

Ender, thanks for the suggestions. I'll stick with the clearing loop. It would be nice if there was a script step that said 'clear all global fields and/or variables' or something along that line, but loops are all good too.

 

I think I'll probably write a separate script, call it 'clear all globals', and have it go through all of the defined global variables that should not have values in between tasks and clear the contents.

Link to comment
Share on other sites

In light of the fact that you have no choice about the stupid repeating fields...

 

Create a new layout. Put only the lousy repeating fields on it. Make sure they are all in the tab order.

 

In your script, go to that layout, then do this simple little loop

 

Go to Field ["g.FieldName"]

Loop

..Set Field [""]

..Go to Next Field

..Exit Loop If [isEmpty (Get(ActiveFieldContents)]

End Loop

 

If you sometimes have fields or repetitions thereof that would already be empty, you would need to adjust this: put a nonrepeating global field on the layout as the first field, and exit loop when Get(ActiveFieldName) is that field's name again.

 

When there are repeating fields on a layout, Go to Next Field goes to the next repetition shown of the same field until it has walked thru them all before going to the actual next FIELD. Underdocumented feature.

Link to comment
Share on other sites

When there are repeating fields on a layout, Go to Next Field goes to the next repetition shown of the same field until it has walked thru them all before going to the actual next FIELD.

Might be worth mentioning that Go to Next Field goes to the next displayed repetition or next field in the Tab order, and then only if the field's (or repetition's) behaviour has been set to allow entry in Browse and/or Find mode.

Link to comment
Share on other sites

Underdocumented feature.

 

Too bad we can't annotate our own Help files - and send them to FM for inclusion next time around!

Link to comment
Share on other sites

Might be worth mentioning that Go to Next Field goes to the next displayed repetition or next field in the Tab order, and then only if the field's (or repetition's) behaviour has been set to allow entry in Browse and/or Find mode.

 

Yes, exactly. You're best off creating a layout for just this purpose.

Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use