Here’s an example of how to call the function (I retrieve the details of one lookup field and then call the above function to populate another lookup field):
1 | var ExistingCase = Xrm.Page.data.entity.attributes.get( "new_existingcase" ); |
2 | if (ExistingCase.getValue() != null ) { |
3 | var ExistingCaseGUID = ExistingCase.getValue()[0].id; |
4 | var ExistingCaseName = ExistingCase.getValue()[0].name; |
5 | SetLookupValue( "regardingobjectid" , ExistingCaseGUID, ExistingCaseName, "incident" ); |
Set the Requirement Level of a Field:
Note: this example sets the requirement level of the Address Type field on the Account form to Required.
Note: setRequiredLevel(“none”) would make the field optional again.
1 | function SetRequirementLevel() { |
2 | var AddressType = Xrm.Page.data.entity.attributes.get( "address1_addresstypecode" ); |
3 | AddressType.setRequiredLevel( "required" ); |
Disable a field:
1 | function SetEnabledState() { |
2 | var AddressType = Xrm.Page.ui.controls.get( "address1_addresstypecode" ); |
3 | AddressType.setDisabled( true ); |
Hide a field:
2 | var name = Xrm.Page.ui.controls.get( "name" ); |
3 | name.setVisible( false ); |
Hide a nav item:
Note: you need to refer to the nav id of the link, use F12 developer tools in IE to determine this
1 | function hideContacts() { |
2 | var objNavItem = Xrm.Page.ui.navigation.items.get( "navContacts" ); |
3 | objNavItem.setVisible( false ); |
Hide a Section:
Note: Here I provide a function you can use. Below the function is a sample.
1 | function HideShowSection(tabName, sectionName, visible) { |
2 | Xrm.Page.ui.tabs.get(tabName).sections.get(sectionName).setVisible(visible); |
5 | HideShowSection( "tab_5" , "tab_5_section_4" , true ); |
Save the form:
1 | function SaveAndClose() { |
2 | Xrm.Page.data.entity.save(); |
Save and close the form:
1 | function SaveAndClose() { |
2 | Xrm.Page.data.entity.save( "saveandclose" ); |
Close the form:
Note: the user will be prompted for confirmation if unsaved changes exist
Determine the Form Type:
Note: Form type codes: Create (1), Update (2), Read Only (3), Disabled (4), Bulk Edit (6)
1 | function AlertFormType() { |
2 | var FormType = Xrm.Page.ui.getFormType(); |
3 | if (FormType != null ) { |
Determine the GUID of the current record:
2 | var GUIDvalue = Xrm.Page.data.entity.getId(); |
3 | if (GUIDvalue != null ) { |
Determine the GUID of the current user:
1 | function AlertGUIDofCurrentUser() { |
2 | var UserGUID = Xrm.Page.context.getUserId(); |
3 | if (UserGUID != null ) { |
Regards,
Imran
[MVP CRM] = https://mvp.support.microsoft.com/profile/imran.mustafa
MSN/IM= mscrmexpert@gmail.com
SKYPE= mscrmexpert
BLOG= http://microsoftcrm3.blogspot.com
Linkedin = http://www.linkedin.com/in/mscrmexpert
Twitter = @mscrmexpert