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)

JavaScript to Validate Editable Grids

(0) ShareShare
ReportReport
Posted on by 334

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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    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

  • lawix10 Profile Picture
    334 on at

    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.

  • lawix10 Profile Picture
    334 on at

    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
    334 on at

    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.

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you can refer to below blog.

    dynamicscrmcoe.com/field-validation-editable-grids

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

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

  • lawix10 Profile Picture
    334 on at

    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.

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