cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Users Online
Currently online: 228 members 3,881 guests
Recent signins:
Please welcome our newest community members: