cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Submit Collection to Dynamics 365 CRM

I am trying to submit a collection to Dynamics 365 CRM. What code do I use in the OnSelect property for a button to submit a collection to Dynamics 365 CRM?

 

Details: I am creating an app for our sales to team to take to trade shows that can take contact information and store it to a collection when they do not have access to wifi or cell service. And I want to have a button that they can press that will submit the collection to CRM when they regain access to wifi or cell service. The collection I am creating is called ContactsToPost.

 

This is what I have so far. Am I on the right track? I am mostly just looking for feedback on the ForAll line.

 

If(Connection.Connected,
      ForAll(ContactsToPost, Patch(Contacts_1, Defaults(Contacts_1), ContactsToPost)); 
      Clear(ContactsToPost);
      Collect(ContactsToPost, {FirstName: FirstName.Text, LastName: LastName.Text, Email: Email.Text});
      SaveData(ContactsToPost, "ContactsToPost");
      UpdateContext({statusText: "Online data"})
  );
  UpdateContext({resetNewContact: true});
  UpdateContext({resetNewContact: false})
1 ACCEPTED SOLUTION

Accepted Solutions
v-micsh-msft
Community Support
Community Support

Hi @Anonymous,

 

The patch function within the forall may not work.

The third parameter for patch should be record, not a table.

Patch function in PowerApps

The correct way for the patch should be the following:

 

Patch(contacts_1,
          Defaults(contacts_1),
         {Item:ContactsToPost.Item,Name:ContactsToPost.Name}
       )

The third parameter in Patch would require a record type, not table type.

Besides, for the If function, it seems there is no corresponding "offline" formula defined.

Adding the corresponding blog for reference:

Building offline apps with new PowerApps capabilities

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-micsh-msft
Community Support
Community Support

Hi @Anonymous,

 

The patch function within the forall may not work.

The third parameter for patch should be record, not a table.

Patch function in PowerApps

The correct way for the patch should be the following:

 

Patch(contacts_1,
          Defaults(contacts_1),
         {Item:ContactsToPost.Item,Name:ContactsToPost.Name}
       )

The third parameter in Patch would require a record type, not table type.

Besides, for the If function, it seems there is no corresponding "offline" formula defined.

Adding the corresponding blog for reference:

Building offline apps with new PowerApps capabilities

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Michael,

 

Thank you for your help. Using a record and not a table for the 3rd paramater solved it. This is what I ended up doing and it works beautifuly:

 

If(Connection.Connected,
      ForAll(ContactsToPost, Patch(Contacts, Defaults(Contacts), {firstname: FirstName, lastname: LastName, emailaddress1: Email, mobilephone: Phone, jobtitle: JobTitle})); 
      Clear(ContactsToPost);
      Collect(ContactsToPost, {FirstName: FirstName.Text, LastName: LastName.Text, Email: Email.Text, Phone: Phone.Text, JobTitle: JobTitle.Text});
      SaveData(ContactsToPost, "ContactsToPost");
      UpdateContext({statusText: "Online data"})
  );

Thanks again!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (5,442)