I create an item id in k2 using BF, how do I know the new id number of the item?

  • Colombiamed
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 14
  • Thank you received: 0

Colombiamed created the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

I create an item in k2 using BF and its integrator, how do I know the new id number of the item?

Because I need this new id number to make insert a new item in the table k2_tags_ref which containts a tagid and the itemeid.

Thanks
#240578
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

Hi,

in the Finalize Code at the bottom of your rule, this should give you the last insert id for the selected table:
// this is directly executed after the integration fired
$db = JFactory::getDbo();
$id = $db->insertid();

// from here you can add additional PHP code to use with the id for the k2_tags_ref table

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240586
  • Colombiamed
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 14
  • Thank you received: 0

Colombiamed replied the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

Using mysql, I made an example inserting a row in the gqp_k2_tags_xref with two values
tagID = 4
itemID = 43

INSERT INTO `test1124`.`gqp_k2_tags_xref` (`id`, `tagID`, `itemID`) VALUES (NULL, '4', '43');

Then in a rule that I created with the integrator to insert data in the table gqp_k2_items, I wrote in this the Finalize Code, but it did not work.

// this is directly executed after the integration fired
$db = JFactory::getDbo();
$id = $db->insertid();

$tag = ff_getSubmit(`depar`);
$sql "INSERT INTO #test1124.gqp_k2_tags_xref` (`id`, `tagID`, `itemID`) VALUES (NULL ".$tag .",". $id ." );"

$db = JFactory::getDbo();
$db -> setQuery($sql);
$db ->query();

//depar is the name of an element which type is Select form list
#240828
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

Hi,

it should be something like this:
$tag= '';

$db = JFactory::getDbo();
$id = $db->insertid();

foreach($rule['items'] As $item){
      if( $item['data'][_FF_DATA_NAME] == 'depar' ){ // the actual field name
          $tag= $item['data'][_FF_DATA_VALUE];
          break;
      }
}

if($id && $tag != ''){

     $sql "INSERT INTO `#test1124.gqp_k2_tags_xref` (`id`, `tagID`, `itemID`) VALUES (NULL ".$db->quote($tag) .",".$db->quote( $id ) ." );"

     $db->setQuery($sql);
     $db->execute();
}

With your table definition I think this isn't correct, I assume you mean

#__gqp_k2_tags_xref

But whatever the tablename is, it should start with #_ as a db prefix placeholder.

Regards,
Markus

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240838
  • Colombiamed
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 14
  • Thank you received: 0

Colombiamed replied the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

Thanks

I am sending you this image to explain you that depar is the name of an element of the form that I am woking with.

the type of this element is select form list.
Thanks.
#240867
Attachments:
  • Posts: 8370
  • Karma: 164
  • Thank you received: 666

TheMuffinMan replied the topic: I create an item id in k2 using BF, how do I know the new id number of the item?

Since the name (not title) of "Depar" is starting uppercase you will need to use it uppercase in my code from above, too:
if( $item['data'][_FF_DATA_NAME] == 'Depar' ){ // the actual field name

===========================
If you are happy, please leave us a small review here to keep us motivated:
(Please turn off your VPN and local Apache prior reviewing as your review might get blocked)

⭐⭐⭐⭐⭐ BreezingForms: extensions.joomla.org/extension/contacts...orms/breezing-forms/
⭐⭐⭐⭐⭐ ContentBuilder: extensions.joomla.org/extension/authorin...tion/contentbuilder/

===========================
Satisfied?
Get a membership!
===========================
#240909
Moderators: ForumSupport
Time to create page: 0.107 seconds

We Are Doing Our Part

Massive discounts on all of our extension subscription plans to help you and your business in these times.

Get Your Subscription Here

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

We are doing our part and support your business with extremely low prices -- For example 6-Months-Subscription for only $9 USD. For as long as necessary.

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!