Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript to Validate Editable Grids

(0) ShareShare
ReportReport
Posted on by 332

I have a JavaScript that Validates Phone number and Postal Code. This function works for the form.

But have tried to apply it to an editable grid but nothing happens.

Because editable grids are subgrids..The Validation in on address entity and works on the address form.

But the editable grid is on the contact form as a subgrid..so i think getting the control is the main issue.

Using the concept of OOP in the JavaScript and the functionality works so the focus in on the editable grid.

function Form_onload() {

	// formats Phone number and fax field
	ValidatePhoneNumber();
	Xrm.Page.getAttribute("new_phonenumber").addOnChange( ValidatePhoneNumber);
	Xrm.Page.getAttribute("new_faxnumber").addOnChange( ValidatePhoneNumber);

	//Validates Postal Code
	ValidatePostalCode();
	Xrm.Page.getAttribute("new_postalzipcode").addOnChange(ValidatePostalCode);
	Xrm.Page.getAttribute("new_countryid").addOnChange(ValidatePostalCode);
}

// Calls the Format Phone Number method in the Main class
function ValidatePhoneNumber(fieldname)
{
	validateAndFormatPhoneNumber(fieldname);
}

// Calls the Format Postal code method in the Main class
function ValidatePostalCode()
{
	reformat_postalcode("new_postalzipcode", "new_countryid");	
}

// Clears the Province field when Country is Changed
function ClearProvince() 
{   
	Xrm.Page.data.entity.attributes.get("new_provincestateid").setValue(null);
}

on the editable grid have added the JavaScript and also passed the schema name of the address detail. This is why i think its not connecting because its another entity.

I can rewrite  JavaScript , but how can i get the control from the editable grid and validate.

address-detail.PNG

*This post is locked for comments

  • lawix10 Profile Picture
    lawix10 332 on at
    RE: JavaScript to Validate Editable Grids

    Yes this finally solved the Puzzle so I used execution form context, the only disadvantage was that the code was not reusable because of the parameter execution context..so i wrote 3 functions for phone number, cell number and fax number...with the form I could have written one function with a parameter of fieldvalue...any idea to make the code reusable. But the answer solved the problem.

    Regards.

  • Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: JavaScript to Validate Editable Grids

    Hi,

    yes editable grid view only allow one notification per time. I think the msdn stated this in the url we provided.

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: JavaScript to Validate Editable Grids

    Hi,

    you can refer to below blog.

    dynamicscrmcoe.com/field-validation-editable-grids

  • lawix10 Profile Picture
    lawix10 332 on at
    RE: JavaScript to Validate Editable Grids

    Started Something Like this and making little progress.

    function validatePhoneNumber() {
    	
    	var addressSubgrid= Xrm.Page.getControl("AddressDetails").getGrid();
    	console.log(addressSubgrid);
    	var selectedRows = addressSubgrid.getSelectedRows();
    	console.log(selectedRows);
    	var phonenumber = selectedRows.data.entity.attributes.get("new_phonenumber").getValue();
    	console.log (phonenumber);
    		
    }


    The Phone Number throws an error, once I can get the field value and the control value then the problem is solved, also the gridcell control.

  • lawix10 Profile Picture
    lawix10 332 on at
    RE: JavaScript to Validate Editable Grids

    Thanks Ravi , but it still a bit confusing compared to the form.

    I figured you start with Grid Control to get the Subgrid.

    Then Grid Attribute to get the Value: the grid attribute uses Grid.getSelectedRows

    and then finally Grid cell to display the notification? so editable grid cannot have more than one notification?

    I can use alert then because the editable grid has more than one value to be validated, Phone , Fax and Postal Code.

    Please do you have any practical example.

    not with the logic of my javascript but for getting a value and setting notification.

    Regards.

  • lawix10 Profile Picture
    lawix10 332 on at
    RE: JavaScript to Validate Editable Grids

    Thanks Alex , but it still a bit confusing compared to the form.

    I figured you start with Grid Control to get the Subgrid.

    Then Grid Attribute to get the Value: the grid attribute uses Grid.getSelectedRows

    and then finally Grid cell to display the notification? so editable grid cannot have more than one notification?

    I can use alert then because the editable grid has more than one value to be validated, Phone , Fax and Postal Code.

    Please do you have any practical example.

    not with the logic of my javascript but for getting a value and setting notification.

    Regards.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: JavaScript to Validate Editable Grids

    Hi ,

    if you want to manipulate the JS via editable gridview, you must follow the editable grid view method.

    msdn.microsoft.com/.../mt788311.aspx

    and you have to make sure every fields that you used in a JS must exist in View also.

    alexmscrm.blogspot.my/.../dynamics-365-editable-girdview-and.html

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: JavaScript to Validate Editable Grids

    Hi Adeyemi,

    There is already a list of supported methods available to work with editable grid.

    Have a look here: msdn.microsoft.com/.../mt788311.aspx

    Hope this helps.

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 Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,375 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans