Fill in lookup field once record created
-
I am creating records in Dataverse from functions.php, but I am not understanding how to actually UPDATE a record that was just created.
After WooCommerce completes an order, I create the account record in Dataverse:
$order = wc_get_order($order_id);
$client = ConnectionService::instance()->getClient();
$account = new Entity( ‘account’ );
$account[‘name’] = $order->get_billing_company();
$account[‘address1_line1’] = $order->get_billing_address_1();
$account[‘address1_line2’] = $order->get_billing_address_2();
$account[‘address1_city’] = $order->get_billing_city();
$account[‘address1_stateorprovince’] = $order->get_billing_state();
$account[‘address1_postalcode’] = $order->get_billing_postcode();
$account[‘address1_country’] = $order->get_billing_country();
$account[‘telephone1’] = $order->get_billing_phone();$accountId = $client->Create( $account );
Then I create a contact:
$contact = new Entity( ‘contact’ );
$contact[‘firstname’] = $order->get_billing_first_name();
$contact[‘lastname’] = $order->get_billing_last_name();
$contact[’emailaddress1′] = $order->get_billing_email();
*** $contact[‘parentcustomerid’] = $accountId; ***$contactId = $client->Create( $contact );
It all works great (thanks George and team!) — except for the starred line above. I want to link the contact to the account just created. Then I also want to update the Account to have the primary contact be the contact just created.
I don’t understand how to do those two things.
Any guidance would be really helpful.
Thank you.
Joe
- The topic ‘Fill in lookup field once record created’ is closed to new replies.