cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dtedwards
Helper I
Helper I

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
BenDenBlanken
Advocate I
Advocate I

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!

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,717)