Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Monday, October 12, 2020

Model Driven App - Script Error

 Recently during some development, I came across one strange error. One user was getting script error when trying to access connection entity form. 

On connection entity, I added some JavaScript code to filter connection from lookup to limit only for Users and Teams. 

JavaScript Code is working fine when I tried to debug issue. 

After doing some more debugging, I realized user is using different app and that app does not have access to Team entity. 

 Once added Team entity into App, error Fixed, and script worked as designed. 

When designing Model Driven App for consider 

 1. When using JavaScript code to filter lookups to specific entity, specially customer lookup, connection entity from / to lookups, make sure entities used in filter are added in App. 

2. When using JavaScript code to redirect to specific form based on value change / option set change, make sure all forms added in App. 

3.  If entity is using Quick create form, then make sure quick create forms added in App otherwise default main form will be used to create record

 

 


Friday, October 21, 2016

Refresh Form Ribbon to show / hide button based on attribute value

I had an requirement, when contact has phone number, then show Make a Call custom button. 
To fulfill this requirement, I created custom button and added action and enable rule to custom button. 

In my button enable rule I am checking for Phone number attribute, if it has value then show button other wise hide button. My JavaScript function is

whenToShowMakeACall: function () {
        var phoneNo = Xrm.Page.getAttribute('telephone1').getValue();
        if (phoneNo != null)
            return true;
        else
            return false;

    },

This is working fine, when contact record has phone number in record and when that record opened button was shown.
But now requirement changed, customer wants to show button, as soon as Phone number entered.
If want to show button as soon as phone number entered, means I need to either save contact record or need to refresh ribbon. 

I cannot save contact record because, there might be some other required attributes are missing. 

Now only option is to refresh ribbon. Till CRM 2016, there is not any supported method to refresh ribbon.  In MS CRM 2016, now we have JavaScript method to refresh ribbon, This method solved my problem. 

I created one JavaScript method and calling on phone number OnChange event to refresh ribbon. 

refreshRibbonNavigation: function () {
        Xrm.Page.ui.refreshRibbon();

    },


No Phone number - No Make a Call button 


When phone number, showing Make a Call button


With Xrm.Page.ui.refreshRibbon();  method, you can show / hide any button based on attribute value.








Wednesday, March 25, 2015

Access Quick View Form values in JavaScript

Generally if want to access any control or attribute in CRM form script you will use control or attribute name.. For Quick form it is little bit complicated.

If I have Quick form for custom entity new_manufacture, and I added this quick form in new_car entity form.

To access new_manufacturer quick form in car entity form I need to use Quick form name, entity name and attribute name to get value.

To access in JavaScript Quick view, control name should be like
QuickFormname_QuickFormname_EntityName_AttributeName



My Quick Form name is : manufactureQuickView
Entity Name : new_manufacture
Attribute: new_Country

if (Xrm.Page.getControl('manufactureQuickView_manufactureQuickView_new_manufacture_new_Country') != null)
{
            var manfCountyctrl = Xrm.Page.getControl('manufactureQuickView_manufactureQuickView_new_manufacture_new_Country');
            var country = manfCountyctrl.getAttribute().getValue();


        }