Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Unanswered

How Can I Query the Parent Record Using JS

Posted on by 10

To check if paymenttype equal credit account [entity form: auto_paymenttype

Then , if payment amount <= resit amount, it will save else > prevent save (popup message invalid: payment amount should lower than resit amount)[entity form: auto_resittype

Hi guys, It could be great if someone could re-code and help me on this.I am new in D365 and JS. Basically, I have entities which is auto_paymenttype and auto_resittype and their parent is Payment. How can I query the parent adjustment record using JS. I have provide my current code, please help me to review it.  I have try everything but so far no luck. Sorry for my unprofessional picture. But I hope you understand it and could help me to code for this situation. Thank you.

6177.pastedimage1630322408936v1.png

function resitApproveAmount(executionContext) {
        try {
        const object = {};
        object.fctx = executionContext.getFormContext();
            object.saveEvent = object.fctx.getEventArgs();
            object.paymentamount = object.fctx.getAttribute("auto_paymentamount").getValue();
            object.resitamount = object.fctx.getAttribute("auto_resitamount").getValue();
            
            
        object.paymenttype = Xrm.Page.getAttribute("auto_paymenttype").getValue();
            if (object.paymenttype != null) {
                object.autoGUID = object.paymenttype[0].id.substring(1, 37);
            }
             
            Xrm.WebApi.retrieveMultipleRecords("auto_paymenttype", "$select=auto_name").then(
            function success(result) {
                  for (var i = 0; i < result.entities.length; i  ) {
                  object.auto_name = result.entities[i]["auto_name"];}
                  if(object.auto_name == "Credit Account"){
                  if (object.paymenttamount >= object.resitamount) {
                    alert("Payment Amount cannot be more than Resit Amount.");
                    object.saveEvent.preventDefault();
                    } 
                else 
                    {object.fctx.data.save();}
                       }
                },
                    
         
                function (error) {
                    console.log(error.message);
                }
            );
        } 
        catch (error) {
            console.log(error);
        }
    }  

  • DavePinch Profile Picture
    DavePinch on at
    RE: How Can I Query the Parent Record Using JS

    Hi Fahran, this was originally posted to Dynamics 365 Guides, which is a mixed reality product for holographic training. I will move your posting to the CRM forum where it should get better visibility.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans