Identify Subform record After Save

Identify Subform record After Save

Unread postby israelwebdev » Tue Sep 23, 2014 6:18 am

I'm writing code to add a new Customer "Lookup" in a subform if a Last Name is provided instead of a CustomerID from the Lookup.
My problem is that I don't know how to reference the subform Primary Key. In the meanwhile, I'm using a user entered semi-unique value RawMICR, but it's not as good as the Primary Key CheckID

Here's the code:
Code: Select all
foreach(nuSubformArray('Checks_subform', false) as $i=>$row){
   if($nuHash[$row.'CustomerID'] == '' && $nuHash[$row.'NewCustomerLast'] != ''){
      if($nuHash[$row.'RawMICR'] != '') {
         $sql1 = "INSERT INTO Customers (CustomerID, cus_number, cus_type, CustomerFirst, CustomerLast,CustomerCountry, ForeignCountry, Active, OFACVerified) VALUES
                  (?, ?, ?, ?, ?, 'ISRAEL', 'USA', '1', '0')";
         $CustomerID = nuID();
         $q1 = nuRunQuery($sql1, array($CustomerID, nuNextNumber('Customer_number'), ($nuHash[$row.'NewCustomerFirst']=='' ? 'Company' : 'Individual'), $nuHash[$row.'NewCustomerFirst'] ,$nuHash[$row.'NewCustomerLast'] ), true);
         $sql2 = "UPDATE Checks SET CustomerID = ? WHERE RawMICR = ? AND TransID = ?";

         $search = array ($CustomerID, $nuHash[$row.'RawMICR'],'#RECORD_ID#');
         $r=nuRunQuery($sql2, $search);

1. Is this the right approach?
2. How can I get the subform Primary Key?
3. I tried using the $q1 as returned by using isInsert parameter of nuRunQuery, but it returned 0. Is this an issue with the code, or my setup? Customers does not have its own auto_increment, but uses Customer_number table as advised.

Posts: 21
Joined: Fri May 23, 2014 1:38 am

Re: Identify Subform record After Save

Unread postby admin » Mon Oct 20, 2014 3:47 pm


I would do what you want on After Save.

That way you can loop through all the records as a record set who's Primary Key will be in each row.

Primary Keys for new subform records won't have Primary Keys until then anyway.

Site Admin
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Return to Custom Code

Who is online

Users browsing this forum: No registered users and 2 guests