Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Need to publish record from two different table

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi All,

 I am having a requirement to publish CustTable and VendTable record into single data entity with ODATA.

Both table will contain a identifier and ODATA will pass the query with identifier. Result set should contain record from both the tables.

can anyone suggest the approach to do the same. 

e.g. for a identifier there are 2 records in CustTable and 2 Records in VendTable so the result set should be all 4 records tagged to the identifier.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Need to publish record from two different table

    thanks martin. just tried with union query and created a view and attached it to data entity and able to get the required fields: AccountType,Name,Address,Email,PaymentMethod,BankAccountId,BankAccountNumber,D365AccountNumber.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    RE: Need to publish record from two different table

    The idea of using existing entities and merging results is simple.

    Imagine that you have a method in the external system which should obtain both customers and vendors and return them as a single data set. Your idea about the implementation is calling a single OData service and returning what you get from it.

    Pseudocode:

    getCustomersAndVendors(_ID)
    	combinedData = OData.CustomersAndVendors.Where(...)
    	
    	result.addRecords(combinedData) // Converting to a format expected by the external system
    	
    	return result

    But you could make one call to get vendors and another to get customers and put both sets of data to an object returned from the method. From caller's point of view, the method behaves exactly as before - we changed mere implementation details, but not the contract.

    Pseudocode:

    getCustomersAndVendors(_ID)
    	customers = OData.Customers.Where(...)
    	result.addRecords(customers)
    	
    	vendors = OData.Vendors.Where(...)
    	result.addRecords(vendors)
    	
    	return result

    Fetching vendors in postLoad() of customer entity is impossible for many reasons. The whole purpose of the method is different, it's called at different times than you think (once for every customer meeting the criteria, i.e. maybe never, maybe many times), you can't use it for adding records and even if it all worked, you would get could get result that makes no sense (because it would claim that these vendors are customers).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Need to publish record from two different table

    Also is there any way in the postLoad() method for customer entity i could write the logic to fetch the record from vendor entity and publish both records ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Need to publish record from two different table

    I understand that they are different entities and should not be merged but the current external system is creating the records as a customer and vendor both. in the same way we just need to expose the common records. e.g AccountType,Name,Address,Email,PaymentMethod,BankAccountId,BankAccountNumber,D365AccountNumber.

    Can you please also elaborate or give a reference for using the existing entity and combine the result?

  • Martin Dráb Profile Picture
    Martin Dráb 230,503 Most Valuable Professional on at
    RE: Need to publish record from two different table

    I don't that putting customers and vendors to a single entity makes a good sense. They're logically two distinct entities and they should be (and are) implemented as two distinct data entities.

    Why don't you simply call the existing entities separately and combine the results?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,431 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans