Skip to main content

Notifications

Dynamics 365 Community / Forums / Sales forum / PowerFx Issue - Child ...
Sales forum
Answered

PowerFx Issue - Child Records not being created

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!
Categories:
  • 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

Helpful resources

Quick Links

Dynamics 365 Community Update

Welcome to the inaugural Community Platform Update. As part of our commitment to…

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Community Spotlight of the Month

Kudos to Mohana Yadav!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,115 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 227,971 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans