Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Page Validator not working in Webform

(0) ShareShare
ReportReport
Posted on by 117

i m trying to put a page validator to check if there are records in the subgrid. If there is atleast one record in the subgrid it should progress to the next page otherwise it has to throw error. I have implemented a similar code ina different page and it is working fine. but for a different webform step this code isnt working. Can someone please tell me how we can debug a validator. My code is below


$(document).ready(function () {

if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "SchoolPlacementvalidator";
newValidator.controltovalidate = "SchoolPlacement";
newValidator.errormessage = "<a href='#SchoolPlacement'>At least one Qualification item must be added to progress.</a>";
newValidator.evaluationfunction = function () {
var SchoolPlacement = $("#SchoolPlacement table tbody tr").length;
if (SchoolPlacement === 0) {
return false
}
else {
return true;
}

};
Page_Validators.push(newValidator);


});

*This post is locked for comments

  • Suggested answer
    Irena Benja Profile Picture
    414 on at
    RE: Page Validator not working in Webform

    Hi edev,

    Whenever there are no records on a list there is a message showing that can be the default one or some customized from your size.

    Maybe you can work with : contains("no data found"), so finding the presence of a text instead of the table rows.

    Something like this:

     $(".entity-grid.entitylist").on("loaded", function () {
     if($('span:contains("your txt")')){
    //your logic
     }
     });

    Hope it helps!

  • edev Profile Picture
    117 on at
    RE: Page Validator not working in Webform

    Hi Nicholas, yes it is a javascript code and its a jquery call from client side to the script which resides in app server. I have resolved the issue by a temporary fix by disbaling the button until atleast one record is added to the subgrid.

  • Nicholas Hayduk Profile Picture
    2,863 on at
    RE: Page Validator not working in Webform

    Sorry, I'm not quite following.

    The code you provided is JavaScript, which means it should run client-side (in the browser).  Where did you add the code to your Portal?  It should be added via the Custom JavaScript field on the Web Form Step.

    Once you have it in the right spot, you should be able to find it in your browser's Developer Tools, and then hopefully by putting a breakpoint there, the breakpoint will be hit when you click the submit button.

    Nick

  • edev Profile Picture
    117 on at
    RE: Page Validator not working in Webform

    Hi Nicholas, it does not give any error and it proceeds to the next page. The problem with my code, we have put the code in app server and calling it in the respective steps and i m not able to debug the code inserting breakpoints. And also i tried to insert an alert and that doesnt work.

  • Nicholas Hayduk Profile Picture
    2,863 on at
    RE: Page Validator not working in Webform

    Hi,

    When you say it doesn't work, does it give an error?  Or does it just let you proceed even if there are no rows in the table?

    As Mahender suggested, you'll probably need to use Developer Tools (F12) to get to the bottom of it.  I'd first put a breakpoint on the [if (SchoolPlacement === 0)] line of code, and make sure it is getting there when you click submit, and if it's giving you the value you'd expect.

    Nick

  • edev Profile Picture
    117 on at
    RE: Page Validator not working in Webform

    Hi Mahendar, thanks for responding back. I checked on the console already and it is working fine and giving me the right count.

  • Mahendar Pal Profile Picture
    45,095 on at
    RE: Page Validator not working in Webform

    Hi,

    I will suggest you to use chrome Developer tools and first check your code is working fine or not under the console

    $("#SchoolPlacement table tbody tr").length;

    it will help you to troubleshoot.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans