cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dtedwards
Level: Powered On

CDS to Create an Address in Dynamics 365 Online

Has anyone tried to use the CDS to Patch into the OOB Addresses entity?

I'm not sure how to target the parent Contact record.

The PowerApps is launched using a button and some JavaScript from Dynamics that passes the GUID of the Contact.

When the PowerApp launches it creates a Collection using the current address information.

The user then updates the address 1 fields on the Contact using a form in the PowerApp. They hit submit which uses a simple SubmitForm to update the Contact. OnSuccess of that form submission, the code below runs to Patch the Addresses entity with the old address information.

You'll notice I have three lines commented out. Originally this was built using the Dynamics 365 connector that is not available in the GCC - we're working to migrate this app to the GCC. With these lines commented out it successfully creates the new address record, but it's not tied to the Contact.

Any help is appreciated!

Code below:

ForAll(ContactInfoBefore,
Patch([@Addresses],
Defaults([@Addresses]),
{
    //_parentid_type: "contacts",
    //parentid: contactid,
    //addresstypecode: address1_addresstypecode,
    primarycontactname: address1_primarycontactname,
    line1: address1_line1,
    line2: address1_line2,
    city: address1_city,
    stateorprovince: address1_stateorprovince,
    country: address1_country,
    county: address1_county,
    postalcode: address1_postalcode,
    po_status: 'Status (Addresses)'.Previous,
    po_startdate: po_address1startdate,
    po_enddate: DateAdd(
        Now(),
        23,
        Hours
    )
}
)
);  

 

2 REPLIES 2
Highlighted
BenDenBlanken
Level: Powered On

Re: CDS to Create an Address in Dynamics 365 Online

Hi,

 

Yesterday I answered a similiar question here.

The parentid you are trying to enter is a polymorphic field. In this case of the type customer. In fields like this you can add an account or a contact. Sadly the CDS connector does not allow us to enter this field directly (yet). We need to

use Relate to set the customer field.

See this screenshot below, where ModelDrivenFormIntegration.Item is a Case entity. The "Tasks" is the relationship name.

OnSelectScript.jpg

 

Let me know if this helps!

dtedwards
Level: Powered On

Re: CDS to Create an Address in Dynamics 365 Online

I am doing this within a ForAll() function, so I can't use Set().

 

I put the Relate() function into where you have Set(). I'm thinking this should do the same thing.

 

Now I'm getting an error on the Patch(): "The requested operation is invalid. Server Response: Parent id not set for address type 1071"

 

Seems like 'Parent' is required, but since 'Parent' is Polymorphic I can't set anything to it...

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Users online (9,739)