web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

I'm trying to add some js code to react to the change of a field located in the business process flow (header) but I can't find where to put my code..

(0) ShareShare
ReportReport
Posted on by

Hi, as you probably guessed I am new to Microsoft Dynamics.

I've been trying to add a filter on a lookup depending on the option you chose in an option set, but I can modify that option set both from the business process flow located in the header and from the body of my form.

I tried adding an OnChange function to the field located in the body of the form, but I'm not sure it applies to the (same) field located in the business process flow in the header. My code was working before, when I didn't use the business process flow as a way to select the option from the business process flow.

Do you know how to add an OnChange function to a field located in the business process flow?

I also tried using "header_process_" but I didn't success..

Here is the code I used before:

function OnChangeOfExpertType() {
Xrm.Page.getControl("rta_expertname").addPreSearch(function () {
addLookupFilter();
});
}

function addLookupFilter() {
var expertise = Xrm.Page.getAttribute("rta_experttype").getSelectedOption().value;
if (expertise != null) {
fetchXml = "<filter type='or'><condition attribute='new_typedelexpert' operator='eq' value='" + expertise + "' />"+
"<condition attribute='new_typedelexpert2' operator='eq' value='" + expertise + "' />"+
"<condition attribute='new_typedelexpert3' operator='eq' value='" + expertise + "' />"+
"<condition attribute='new_typedelexpert4' operator='eq' value='" + expertise + "' />"+
"</filter>";
Xrm.Page.getControl("rta_expertname").addCustomFilter(fetchXml);
}
}

PS: Sorry if my english is bad

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hello Vincent,

    In regards to the onchange of a field on business process flow, you just need to add the event on the field present in the form body. When you change the field value on business process flow, the field on the body will change and the opposite occurs as well.

    Therefore, it is not possible to add onchange event on the business process flow and the onchange event that you specify on the body field will work.

    You just need to guarantee that the field is in the form body and has the onchange event.

    Cheers!

    Pedro Pisco

  • Verified answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi Vincent,

    You can add field from bpf (for which you want to trigger jscript) on form  as well and then trigger on change event of that field. If its not triggering then please check once if changing value of field in bpf changes value in field on form?

    Hope this helps:)

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Vincent,

    You need to maintain both header and body control in that case - try with this -

    function OnChangeOfExpertType() {
    
        if (Xrm.Page.getControl("rta_expertname") != null && Xrm.Page.getControl("header_process_rta_expertname") != null) {
            Xrm.Page.getControl("rta_expertname").addPreSearch(function () {
                addLookupFilter();
            });
    
    
            Xrm.Page.getControl("header_process_rta_expertname").addPreSearch(
           function () {
               addLookupFilter();
           });
        }
    }
    
    function addLookupFilter() {
        var expertise = Xrm.Page.getAttribute("rta_experttype").getSelectedOption().value;
        if (expertise != null) {
            fetchXml = "<filter type='or'><condition attribute='new_typedelexpert' operator='eq' value='" + expertise + "' />" +
            "<condition attribute='new_typedelexpert2' operator='eq' value='" + expertise + "' />" +
            "<condition attribute='new_typedelexpert3' operator='eq' value='" + expertise + "' />" +
            "<condition attribute='new_typedelexpert4' operator='eq' value='" + expertise + "' />" +
            "</filter>";
            Xrm.Page.getControl("rta_expertname").addCustomFilter(fetchXml);
            if (Xrm.Page.getControl("header_process_rta_expertname") != null && Xrm.Page.getControl("header_process_rta_expertname") != undefined) {
                Xrm.Page.getControl("header_process_rta_expertname").addCustomFilter(fetchXml);
            }
        }
    }


    Hope this helps .

  • gdas Profile Picture
    50,091 Moderator on at

    This should  be work if you register your function in the onchange event of the field in the body , try with this which I have shared .

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans