Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

PowerFx Issue - Child Records not being created

(0) ShareShare
ReportReport
Posted on by 15

Hi Community, 

I am digging into PowerFx in Command Bar within Model Driven Apps doing a clone of parent record (Quote) and child records (Quote Lines): 

pastedimage1678489032789v1.png

I am using a With statement to capture the newly created Quote guid to reference in the Quote LInes patch statement: 

With({
     quote_recid:
      Patch(Quotes,
      Defaults(Quotes),
       {
          Name: "Copy of" & Self.Selected.Item.Name,
          'Potential Customer (_customerid_value)': Self.Selected.Item.'Potential Customer (msdyn_account)',
          'Potential Customer (msdyn_account)': Self.Selected.Item.'Potential Customer (msdyn_account)',
           'Primary Contact': Self.Selected.Item.'Primary Contact',
          'Price List': Self.Selected.Item.'Price List',
          Currency: Self.Selected.Item.Currency,
          'Work Order Type': Self.Selected.Item.'Work Order Type',
          'Payment Terms': Self.Selected.Item.'Payment Terms'
        }
      )
    },

//Clone Child Records
Patch('Quote Lines',
  ForAll(Self.Selected.Item.'Quote Lines' As quoteproducts,
    Patch(
      Defaults('Quote Lines'),
      {
         Quote: quote_recid,
        'Quote Product': quoteproducts.'Quote Product',
        Quantity: quoteproducts.Quantity,
        'Price Per Unit': quoteproducts.'Price Per Unit',
        Unit: quoteproducts.Unit,
        'Product type': quoteproducts.'Product type',
        'Sequence Number': quoteproducts.'Sequence Number'

                        }
                      )
                     )
                    );

Notify("Quote Copy of " & Self.Selected.Item.Name & " and its lines have been cloned. Please open the records and update the necessary fields.");
);
Within PowerFX, it does not show any errors so I am not sure where it is erroring out. I have a case open with Microsoft but waiting to hear back. 
My copy of the Quote gets created and my notification inside Sales Hub also works. 
Something is wrong with my //Clone Child Records. 
Any peer review here of my code would be appreciated or if there is another approach I could take. 
Thank you!
  • c_edouarde Profile Picture
    c_edouarde 15 on at
    RE: PowerFx Issue - Child Records not being created

    Hi Steve,

    Thanks for the help! You were correct, I was missing required fields Name , Property config., and Product Type and it worked like a charm.

    Appreciate the support!

  • Verified answer
    Steve Zhao2 Profile Picture
    Steve Zhao2 on at
    RE: PowerFx Issue - Child Records not being created

    Hi haciendo_olas,

    Based on my test, this is due to some required columns (Name and Property Configuration) don't have value. Please try this:

    With(
        {
            QuoteId: Patch(
                Quotes,
                Defaults(Quotes),
                {
                    Name: "Copy of" & Self.Selected.Item.Name,
                    Currency: Self.Selected.Item.Currency,
                    'Price List': Self.Selected.Item.'Price List',
                    'Potential Customer (_customerid_value)': Self.Selected.Item.'Potential Customer (msdyn_account)',
                    'Potential Customer (msdyn_account)': Self.Selected.Item.'Potential Customer (msdyn_account)'
                }
            )
        },
    //Clone Child Records
            ForAll(
                Self.Selected.Item.'Quote Lines' As quoteproduct,
                Patch('Quote Lines',
                    Defaults('Quote Lines'),
                    {
                        Quote: QuoteId,
                        'Existing Product': quoteproduct.'Existing Product',
                        Quantity: quoteproduct.Quantity,
                        'Price Per Unit': quoteproduct.'Price Per Unit',
                        Unit: quoteproduct.Unit,
                        'Product type': quoteproduct.'Product type',
                        'Sequence Number': quoteproduct.'Sequence Number',
                        Name:quoteproduct.Name,
                        'Property Configuration':quoteproduct.'Properties Configuration'
                        
                    }
                )
            );
        
        Notify("clone done");
    );
    


    And this is my test result:

    pastedimage1678695905748v1.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans