コード例 #1
0
        /// <summary>
        /// This method is called when user clicks Add button in Related PivotItem
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void abRelatedAdd_Click(object sender, RoutedEventArgs e)
        {
            // Get RelatedData to create related record
            RelatedData relatedData = entityMetadataEx.RelatedEntities.Where(x => x.ReferencingEntity == (CRMGrid.cbLookFor.SelectedItem as EntityMetadataEx).EntityMetadata.LogicalName).First();

            // Create Entity instance to created record, by fulling mapped values.
            Entity targetRecord = await CRMHelper.RetrieveRecordForRelated(record, relatedData, entityMetadataEx);

            // Make id to empty for sure (not mandatory?)
            targetRecord.Id = Guid.Empty;
            // Get Related entity's EntityMetadata
            EntityMetadataEx targetEntityMetadataEx = CRMHelper.EntityMetadataExCollection.Where(x => x.EntityMetadata.LogicalName == relatedData.ReferencingEntity).First();
            // Get fields for create form
            List <FormFieldData> targetFields = await CRMHelper.RetrieveFormFields(targetEntityMetadataEx);

            // Resets all the buttons
            ResetAppBarButtonDisplay();
            // Generate parameters. As this is new record, passing null for record object.
            object[] parameters = new object[] { targetRecord, targetFields, targetEntityMetadataEx };
            CRMHelper.temporaryData = parameters;
            // Then Navigate to RecordModifyPage
            Frame.Navigate(typeof(RecordModifyPage));
        }