Export Parent Company Name

I ended up solving this with custom code using operations hub.

I’m copying over certain values from parent companies to all of their child companies.

I created a company property called “parent company name” (internal id=parent_company_name) and I’m copying the value of the Company Name (name) property in the parent company to the parent_company_name property for all their child companies.

I also left here some other fields I’m copying over: Company Owner (hubspot_owner_id), Solutions Engineer (solutions_engineer), Lifecycle Stage (lifecyclestage), and Account Tier (tier__c) just so you have some examples of how it’s done.

const hubspot = require('@hubspot/api-client');

exports.main = async (event, callback) => {
 // Define Hubspot client
 const hubspotClient = new hubspot.Client({
 accessToken: process.env.insertyouraccesstokenhere 
 });

 let output = "Updated companies: ";

 // Start main logic
 try {
 // Get parent company properties
 console.log('event.object.objectId:', event.object.objectId);
 const parentCompany = await hubspotClient.crm.companies.basicApi.getById(event.object.objectId, ["hubspot_owner_id", "solutions_engineer", "tier__c", "lifecyclestage", "name"]); // What you guys are looking for is the "name" property
 console.log('parentCompany:', parentCompany);
 console.log('parentCompany.properties:', parentCompany.properties);
 const parentProperties = parentCompany.properties;

 // Set properties to update
 const propertiesToUpdate = {
 "hubspot_owner_id": parentProperties.hubspot_owner_id,
 "solutions_engineer": parentProperties.solutions_engineer,
 "tier__c": parentProperties.tier__c,
 "lifecyclestage": parentProperties.lifecyclestage,
 "parent_company_name": parentProperties.name // Copy "name" to "parent_company_name" in child companies
 };

 // Get child companies
 const childCompaniesResponse = await hubspotClient.crm.companies.associationsApi.getAll(event.object.objectId, "company");
 const childCompanies = childCompaniesResponse.results;

 // Update child companies
 for (const childCompany of childCompanies) {
 try {
 if (childCompany.toObjectId) { // Check if childCompany has an id property
 console.log('childCompany.toObjectId:', childCompany.toObjectId);
 const apiResponse = await hubspotClient.crm.companies.basicApi.update(childCompany.toObjectId, { properties: propertiesToUpdate });
 output += childCompany.toObjectId + ", ";

 console.log("Full response object:", apiResponse);
 console.log("Updated child company:", childCompany.toObjectId);
 } else {
 console.error("Child company does not have an id property:", childCompany);
 }
 } catch (e) {
 console.error('API error:', e);
 output += "Error updating company " + childCompany.toObjectId + ", ";
 }
 }

 } catch (err) {
 console.log("Error looking for child companies");
 console.error(err);
 throw err;
 }

 console.log("Output:", output);
 callback({
 outputFields: {
 company_childs: output // You need to also define output in the action output variables settings
 }
 });
}

this shouldn’t be needed, but it works.