Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Web resource not working on two similar fields in same form

Posted on by

Hi  All,

I have created a web resource and used that web resource in a field which is used two times in the same form of an entity. I have to use the same functionality on both the fields. It is working fine with one field but not working with another which is used later below the form. I have used the controls also as below:

Please assist.

var PhoneNoAttribute = Xrm.Page.getAttribute("new_telephonenumber");
var PhoneNoControls = PhoneNoAttribute.controls.get();

for(var i=0; i < PhoneNoControls.length; i++)
{
PhoneNoControls[i].setDisabled(false);
var telephone= Xrm.Page.data.entity.attributes.get("new_providedphonenumber").getValue();
if (telephone == 100000002)
{
Xrm.Page.ui.controls.get("new_telephonenumber").setVisible(true);
Xrm.Page.data.entity.attributes.get("new_telephonenumber").setRequiredLevel("required");
}
else
{
Xrm.Page.ui.controls.get("new_telephonenumber").setVisible(false);
Xrm.Page.data.entity.attributes.get("new_telephonenumber").setRequiredLevel("none");
}
}
}

*This post is locked for comments

  • Suggested answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Web resource not working on two similar fields in same form

    Hi Rakhi Sharma,

    When you place the same field on the form twice, the CRM UI changes the schema name of the field as follows.

    1st field - new_telephonenumber

    2nd field - new_telephonenumber1

    To verify this, please do one of the following:

    1. Put a debugger and check if the field with name -'new_telephonenumber1' exists on the form

    2. Download the Chrome extension by Sonoma Partners (chrome.google.com/.../eokikgaenlfgcpoifejlhaalmpeihfom )

    Once the form loads, go to Dev Console, there will be a new tab named 'CRM DevTools'. In that tab, there will be a button named "Show schema names". Click the button and verify the schema name of the 2nd field on the form.

  • DineshKaushik  Profile Picture
    DineshKaushik 20 on at
    RE: Web resource not working on two similar fields in same form

    Hi Rakhi

    on which event you are running your script ? if it is on change then please add the same script on change of the field.

    Thanks

    Dinesh

  • Rakhi Sharma Profile Picture
    Rakhi Sharma on at
    RE: Web resource not working on two similar fields in same form

    Hi Alex,

    The telephonenumber field is getting visible only once after the field change of ProvidedPhoneNumber is executed. I want this to work twice, as the field 'ProvidedPhoneNumber' is used two times on the form.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Web resource not working on two similar fields in same form

    Hi,

     what exactly is not working?

     BTW, I think you only need to have the for loop like this:

    for(var i=0; i < PhoneNoControls.length; i++)

    {

     PhoneNoControls[i].setDisabled(false);

    }

     it seems the rest can be done only once (does not have to be in the loop):

    var telephone= Xrm.Page.data.entity.attributes.get("new_providedphonenumber").getValue();

    if (telephone == 100000002)

    {

    Xrm.Page.ui.controls.get("new_telephonenumber").setVisible(true);

    Xrm.Page.data.entity.attributes.get("new_telephonenumber").setRequiredLevel("required");

    }

    else

    {

    Xrm.Page.ui.controls.get("new_telephonenumber").setVisible(false);

    Xrm.Page.data.entity.attributes.get("new_telephonenumber").setRequiredLevel("none");

    }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans