Forums: Get key field on copy - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Get key field on copy Rate Topic: -----

#1 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 266
  • Joined: 21-September 07
  • Gender:Male
  • Location:Minnesota, USA

Posted 19 November 2018 - 06:02 PM

Hi all,

I have a list page that allows users to copy a record. I'd like to grab the ID of the record being copied and save it into a session variable. (I will then use this for a select statement so I can do an insert into a details table, giving the new master record the same details records as the copied master).

I assume I will do this in the "Copy page:onload" event, but I can't figure it out. I see in the help info at the top of the event page it says "where - WHERE clause that points to the record to be copied. Example: ID=19". So there it is, but how to I assign this to a session? My lame attempt was this:

XSession.Session["copyid"]=where;

This didn't give me errors, but also didn't work.


UPDATE
Before I posted this I did one last search and found this: http://asprunner.com...cord-is-copied/

It seems I need the "Add page: Before process" event and this code:


if (@$_REQUEST["copyid1"])
$_SESSION["copyid1"] = $_REQUEST["copyid1"];


But that's PHP. Can I/how can I do that in C#?


Thanks for any help.
Tim
0

#2 User is offline   Arkie 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 78
  • Joined: 19-October 15
  • Gender:Male
  • Location:Arkansas

Posted 19 November 2018 - 11:17 PM

Maybe I can get you started as I have a copy record working, but there a couple of gotchas which seem to be related to my lack of knowledge about version 10.

I used the code for a custom record update in an edit page event such as:
++++
dynamic tblitems = GlobalVars.dal.Table("items");
tblitems.Value["itemcode"] = values["itemcode"];
tblitems.Value["description"] = values["description"];
tblitems.Value["vendor"] = values["vendor"];
tblitems.Add();
return false;
++++
I get the copy record part of this, but in version 10, I'm at a loss on how to implement it. This copies the chosen record, but I lose the Edit page function and I haven't figured out how to get both.
There is an option to have a "copy page" in the pages to build section and it puts a small icon next to the edit icon on a list page. BUT.. I haven't figured out how to use it. The icon gets created, but doesn't appear to know it's own destination.
The docs mention something about an "Add (in copy mode)", but don't find any info on it.

~Joe
0

#3 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16109
  • Joined: 03-February 03
  • Gender:Male

Posted 20 November 2018 - 03:49 AM

The idea of having WHERE clause as a parameter is to let you execute SQL query to retrieve the original record.

So you can use something like this:

XSession.Session["copyid"] = tDAL.DBLookup(String.Format("select <keycolumn> from <tablename> where {0}"), where);


@Arkie,

I wish I understand what you trying to achieve or what causes the trouble. Your code has nothing to do with version 10. Probably start a new thread and be descriptive.
Best regards,
Sergey Kornilov
0

#4 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 266
  • Joined: 21-September 07
  • Gender:Male
  • Location:Minnesota, USA

Posted 20 November 2018 - 03:28 PM

@Arkie

Thanks for the reply. I haven't tried to add a copy page in version 10, but will need to do so soon. Hopefully it works.

@admin

Thank you. I get it. The WHERE clause is literally "ID=19" and not just the value "19". Based on that, it does look like the code you provided is exactly what I need. Here is what I ended up with:

XSession.Session["copyid"] = tDAL.DBLookup(String.Format("select ID from dbo.StandingOrders where {0}"), where);



But when I build my project I get this error:

error CS1501: No overload for method 'DBLookup' takes 2 arguments


Maybe the double quote is in the wrong place...? I tried a couple of changes but couldn't get it. Can you help?

Thanks,
Tim
0

#5 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 266
  • Joined: 21-September 07
  • Gender:Male
  • Location:Minnesota, USA

Posted 20 November 2018 - 05:39 PM

I am removing what I previously posted because I was wrong, it wasn't working. I still need to figure out why I get an error from the DBLookup.

Thanks,
Tim
0

#6 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16109
  • Joined: 03-February 03
  • Gender:Male

Posted 20 November 2018 - 10:09 PM

A typo on my side. Here is the correct code:

XSession.Session["copyid"] = tDAL.DBLookup(String.Format("select <keycolumn> from <tablename> where {0}", where));

Best regards,
Sergey Kornilov
0

#7 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 266
  • Joined: 21-September 07
  • Gender:Male
  • Location:Minnesota, USA

Posted 21 November 2018 - 02:30 PM

Thank you (I probably should have been able to figure that out), but now I'm getting an error in the published app. It seems like the "where" parameter is empty. I tried displaying it on the page and I get nothing. And the here is the error I get when I click the copy link:

Value cannot be null.
Parameter name: args

Line 26: XSession.Session["copyid"] = tDAL.DBLookup(String.Format("select ID from dbo.StandingOrders where {0}", where));


I published a test app to the demo site to demonstrate the issue. Here is the link:

http://demo.asprunne.../dbo_Tests/list

Click the copy link to see the error.

I am letting you know this for your info, but for my current needs, I think I have a solution. I realized that there is a "post" value with the copied field's key, so it looks like I can do this:

XSession.Session["copyid"]=MVCFunctions.postvalue("copyid1");

So, unless you tell me this is not a good solution, I think I'll move forward with this.

Thanks, as always!
Tim
0

#8 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16109
  • Joined: 03-February 03
  • Gender:Male

Posted 21 November 2018 - 03:56 PM

I can confirm that in current version of ASPRunner.NET where is empty in Copyonload event. This is a bug and we are working on it.

The method that you use should work just fine.
Best regards,
Sergey Kornilov
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users