projay Posted December 19, 2010 Posted December 19, 2010 This script basically worked with a repeating panel... Since then i have changed from a repeating panel to a portal How can I make this work with PORTAL ROWS. All this does is simply copies a value from FIELD_A and puts it in FIELD_B if a the value in FIELD_C is =>1 This is a loop script so it stops coping the value if FIELD_C is Empty or has a 0. Any help would be great. Thanks Jay. script_copy.zip
dansmith65 Posted December 19, 2010 Posted December 19, 2010 You are still using the field as a repeating field. That is not how you access related records. There are a couple ways to loop through records in a portal... First Method: - go to first portal row (portal must be active, or the only portal on the layout before running this step) - start loop - do what you want with each record (using repetition 1 of the field) - go to next portal row[exit after last] - end loop Second Method: This method uses the GetNthRecord() function. If your portal is not filtered or sorted, then you do not have to go to the portal before running this loop (it will just use the relationship). I find that this method is faster. - go to portal (an field on the portal, the portal's object name, pretty much anything you can do to 'activate' it) - set variable[$_counter; value: 1] - start loop - use GetNthRecord( Related::field ; $_counter ) to access the data for each record - exit loop if[ not isvalid( GetNthRecord( Related::PrimaryKey ; $_counter ) ) - set variable[$_counter; value: $_counter + 1] - end loop
comment Posted December 19, 2010 Posted December 19, 2010 I would suggest a third method, which IMHO is almost always preferable: forget about the portal, go to the related records in their own table, do the loop there and come back when you are done. Second Method: This method uses the GetNthRecord() function. If your portal is not filtered or sorted, then you do not have to go to the portal before running this loop (it will just use the relationship). I find that this method is faster. - go to portal (an field on the portal, the portal's object name, pretty much anything you can do to 'activate' it) - set variable[$_counter; value: 1] - start loop - use GetNthRecord( Related::field ; $_counter ) to access the data for each record - exit loop if[ not isvalid( GetNthRecord( Related::PrimaryKey ; $_counter ) ) - set variable[$_counter; value: $_counter + 1] - end loop I am quite puzzled by this method: First, why do you need to activate the portal? The GetNthRecord() function will return the correct result whether the portal is active or not. In fact, it will return the correct result even if no portal exists. Next, this method can only GET data from the related records - not modify them. You could have achieved the same result much more simply by using one of the aggregate functions, e.g. List ( Related::Field ).
projay Posted December 19, 2010 Author Posted December 19, 2010 The file i attached will only copy data to the first line in the portal is their a way to alter that script so that it will copy to other portal lines? Jay.
dansmith65 Posted December 19, 2010 Posted December 19, 2010 I would suggest a third method, which IMHO is almost always preferable: forget about the portal, go to the related records in their own table, do the loop there and come back when you are done. Thanks comment, my train of thought on this one was clouded by the fact that I was just working on a custom portal row sort feature which needed to interact with the records as they are in the portal, not as they appear in the relationship. First, why do you need to activate the portal? This part mentioned that: "If your portal is not filtered or sorted, then you do not have to go to the portal before running this loop (it will just use the relationship)." I found that GetNthRecord will return values as they are sorted OR filtered in the portal, as long as the portal is active when GetNthRecord is evaluated. Next, this method can only GET data from the related records - not modify them Thanks for catching that; again, I was just using it to get information portal records. I forgot that I ended up having to go to the portal row to set a field. projay... Do you understand what comment and I are talking about? As we just gave you some different methods to use.
projay Posted December 20, 2010 Author Posted December 20, 2010 Hello everyone, Well I think I am more confused now then before I posted this question. Jay
dansmith65 Posted December 20, 2010 Posted December 20, 2010 ok, here is one very direct pointer then... change If[order_lineitem::product_line_total[$_counter] >= 1] to If[order_lineitem::product_line_total >= 1] That's one of the problems with your script. That's what I was referring to when I said you are still using the field as a repeating field.
projay Posted December 20, 2010 Author Posted December 20, 2010 Hi Dan, It only sets field on the first row of portal and not the other. Attached is my exact script. Jay. Script not working on portal rows.zip
bruceR Posted December 20, 2010 Posted December 20, 2010 You're still ignoring the advice. You're still treating the field as a repeating field - you are using square bracket syntax. Drop the [$counter] part.
projay Posted December 20, 2010 Author Posted December 20, 2010 After adjusting...Now I have to escape out of the script and it only replaces the first line. Adjusted script attached. Script not working on portal rows_adjusted_1.zip
dansmith65 Posted December 21, 2010 Posted December 21, 2010 ok, now that you got the repeating value out of there... Go back to my first post and create the loop as I suggested (or use comment's suggestion of going to the related records and looping through them there). hint: you need to increment your $_counter variable in the loop; that is the reason you "have to escape out of the script"
Recommended Posts
This topic is 5087 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 accountSign in
Already have an account? Sign in here.
Sign In Now