Archive
Canvas App | Dataverse | Distribute columns to multiple forms and Patch
When working with large tables in Canvas App’s Phone layout Forms, it would be counterintuitive to place all the fields in a single form. In below screen, user has to scroll a lot to fill all the details.
In this article, lets see how we can simplify above screen by distributing fields in multiple forms and finally use the Patch function to save the information in to Dataverse from all the forms.
I am taking the OOB ‘Contact’ table in this scenario and distributing fields in to 3 screens (i.e., Basic Details, Contact Details and Additional Details). Lets get started.
- Create a new Canvas App from Maker portal.
- From the ‘Data’ tab, Select ‘Entities -> Current environment -> Contacts’ table and add to the App.
- Add 3 screens (Basic Details, Contact Details and Additional Details) to distribute fields.
- In the Basic Details screen (i.e., scrBasicDetails), add a new Form (i.e.,formBasicInfo) and add following fields from ‘Contact’ Datasource.
- Add a Button, to navigate to next screen (i.e., scrContactDetails). Add following formula on ‘OnSelect’ of button.
- Similarly, In the Contact Details screen (i.e., scrContactDetails) add a new Form (i.e.,formContactDetails) and add following fields from ‘Contact’ Datasource.
- Add a Button, to navigate to next screen (i.e., scrAddlDetails) by triggering ‘Navigate’ function on ‘OnSelect’ of button.
- In the last ‘Additional Details’ (i.e., scrAddlDetails) screen, add a new Form (i.e.,formAddlDetails) and add ‘Attachments’ field to capture and store documents to Dataverse.
- Since this is our final screen, Add a Button to Submit the data to Contact table in Dataverse using following ‘Patch’ function.
- Post submit refresh the forms using NewForm() function.
- Display a banner message using ‘Notify’ function.
- Finally Navigate back to first screen (i.e., scrBasicDetails) using Navigate() function.
- Combined formula is as below.
// Patch : Use Patch with the Defaults function to create records.
// form.Updates : Gets the data from the fields presented on the from.
Patch(
Contacts,
Defaults(Contacts),
formBasicInfo.Updates,
formContactDetails.Updates,
formAddlDetails.Updates
);
// NewForm : Sets the form mode to Insert so that you can submit a new Contact.
NewForm(formBasicInfo);
NewForm(formContactDetails);
NewForm(formAddlDetails);
// Notify : Display notification
Notify(
"Contact submitted successfully",
NotificationType.Success
);
// Navigate : Navigates to first screen
Navigate(scrBasicDetails);
- Run the App, provide details and navigate to next screen and upload images and finally click ‘Submit’ to save data to Dataverse.
- Now go to Dataverse using Model Driven App and open the Contact -> Audit History, to prove only one transaction triggered with our Patch function.
š
Set Regarding Lookup and open a new Task form ā USD
I was exploring USD and tried below scenario.
From a new Account Session
- Add a āCreate Taskā Agent Script Answer.
- On click, open Task form in a new Tab, pre-populated with āRegardingā lookup with Account.
I had a tough time to set āRegardingā look up with āCustomerā using āNew_CRM_Pageā UII Action.
I could achieve with āNavigateā UII Action.
In the URL, I read Account details from Context and set
- regardingobjectid = Account GUID
- regardingobjectidname = Account Name
- regardingobjecttypecode = Schema Name
URL:
/main.aspx?etn=task&extraqs=regardingobjectid%3D[[$Context.Id]u+]%26
regardingobjectidname%3D[[$Context.name]u+]%26regardingobjecttypecode
%3D[[account.LogicalName]u+]&pagetype=entityrecord&navbar=off&cmdbar=falseĀ
Exclude ānavbar=off&cmdbar=falseā from URL, if you want CRM tool bar on the new ‘Task’ form.
š
Script error with navigate() statement while navigate between forms ā CRM Jscript
We have a Custom entity with 3 forms and the requirement is to navigate to a different form based on a field value .
So we registered a script on form āloadā event to navigate to a specific form based on an option set value.
Navigation worked as expected except few userās that too when application should take User to āForm 2ā.
Reason and Fix
- We configured new Security Roles recently.
- Our forms were role based and we missed enabling newly added āSecurity Roleā for āForm 2ā.
- By enabling newly added Security Role for āForm 2ā script started working.
š