Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Populate portal rows with summary list values

Featured Replies

Hi there,

 

I'm a bit stuck with something and I'm hoping someone can shed some light on how to achieve what I'm after.

 

I have a database with products and purchase orders.

 

I have a global field that contains product id's in a list format.

 

I am trying to work out how to take that values from the global field list and populate the purchase order line items (which are in a portal on purchase orders) with the list values.

 

I need each list value to be inserted in a new portal row.

 

The number of values in the list would vary each time the action is performed depending on which products were pre-selected.

 

Can anyone help point me in the right direction?

 

Mark 

There is only one way to "populate" portal rows: you must create records in the portal's source table. In your example, you would use a looping script to create a line item record for each value in the global field. However, the new records must also be related to a record in the parent (purchase orders) table. This part is missing from your description. Do you already have a purchase order to which these items should belong?

  • Author

Hi comment,

Thank you for taking the time to reply to my post.

If that's the case I can start the script by creating a purchase order then simply setting the purchase order id in a variable then begin creating records in the purchase order line items and setting the purchase order id match field.

I'm still not clear though how I would extract the product id's from my list into the product id match field for each record in line items.

I get the loop part that's fine, I'm just not sure how to set the product id field in line items with the product ids and then end the loop once the last id has been set.

Mark

I'm still not clear though how I would extract the product id's from my list into the product id match field for each record in line items.

I get the loop part that's fine, I'm just not sure how to set the product id field in line items with the product ids and then end the loop once the last id has been set.

 

The basic idea is that within the loop you maintain an iteration counter that's used to a ) extract values from a list, using GetValue(), and b ) exit the loop once the list has been processed; so, assuming you have a list of IDs in a global field, and adding a bit of error-trapping …

If [ IsEmpty ( SomeTable::gListOfProductIDs ) ]
  Exit Script
End If
Set Variable [ $purchaseOrderID ; PurchaseOrders::PK_purchaseOrderID ]
Go to Layout [ LineItems ]
Loop
  Set Variable [ $i ; $i + 1 ]
  New Record/Request
  Set Field [ LineItems::FK_productID ; GetValue ( SomeTable::gListOfProductIDs ; $i ]
  Set Field [ LineItems::FK_purchaseOrderID ; $purchaseOrderID ]
  Exit Loop if [ $i = ValueCount ( SomeTable::gListOfProductIDs ) ]
End Loop
Set Field [ SomeTable::gListOfProductIDs ; "" ]
Go to Layout [ original layout ]

You could also create line items without leaving the PurchaseOrders layout if you use a portal to a LineItems relationship that allows creation of related records; it wouldn't require setting the PurchaseOrder foreign key, since that would already be part of the relationship definition.

 

On a related note: when populating the global field with product IDs, make sure you ignore / don't add IDs of products that already have a line item for the respective PO. You can use FilterValues to check on the presence of a value in a list, i.e. List ( LineItems::FK_purchaseOrderID ) ; this will save you from having to make that test when creating new line items with the above script.

 

EDIT: SomeTable::gListOfProductIDs in the Exit Loop

I'm just not sure how to set the product id field in line items with the product ids and then end the loop once the last id has been set.

 

I was just about to answer this when eos posted his answer, so I'll just make a few mods:

Set Variable [ $purchaseOrderID ; PurchaseOrders::PK_purchaseOrderID ]
Set Variable [ $productIDs ; AnyTable::gListOfProductIDs ]
Go to Layout [ LineItems ]
Loop
    Set Variable [ $i ; $i + 1 ]
    Exit Loop If [ $i > ValueCount ( $productIDs ) ]
    New Record/Request
    Set Field [ LineItems::PurchaseOrderID ; $purchaseOrderID ]
    Set Field [ LineItems::ProductID ; GetValue ( $productIDs ; $i ]
End Loop
Set Field [ AnyTable::gListOfProductIDs ; "" ]
Go to Layout [ original layout ]

Note that we are assuming that the global field contains a return-separated list of the selected products' IDs - such as you would get if the field were formatted as a checkbox set..

 

 

 

  Exit Loop if [ $i = ValueCount ( $productList ) ]

 

I don't see that the $productList variable is defined anywhere.

I don't see that the $productList variable is defined anywhere.

 

Right; I started out with that list variable, then noticed that the list is supposed to be stored in a global field, and forgot to change that bit. Good catch.  :smile:

Right; I started out with that list variable, then noticed that the list is supposed to be stored in a global field

 

I have loaded it into a variable anyway, because I suspect it's a hair faster that way.

  • Author

Eos and comment,

Thank you for your suggestions.

I'll apply that today and come back with the results.

Mark

  • 2 months later...
  • Author

I finally got around to implementing the suggested script and made a few tweaks so that it adds the line items directly through the portal.

 

Thanks again for the suggestion - a very clever yet simple and effective solution.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.