Customer Engagement & Dynamics CRM Forum

Expand all | Collapse all

Custom Button does nothing in Classic, Works in UCI

  • 1.  Custom Button does nothing in Classic, Works in UCI

    SILVER CONTRIBUTOR
    Posted 25 days ago
    We have some custom buttons that generate activities for many of our entities.

    The only difference in behavior between classic interface and UCI is when trying to open a new activity from the associated activity view.

    I have the following code in the JavaScript being executed from the command:

    function OpenNewActivityFromMain(primaryControl) {
            
        var entityFormOptions = {};
        var parameters = {};
        
        var itemReference = primaryControl.data.entity.getEntityReference();
        
        entityFormOptions["entityName"] = entityLogicalName;
        entityFormOptions["createFromEntity"] = {entityType: itemReference.entityType, id: itemReference.id, name: itemReference.name};
     
        Xrm.Navigation.openForm(entityFormOptions, parameters);    
     
    }
    The code above is used for buttons in the Main Form ribbon for the entities, and it works for both UCI and Classic interface.
    The same code is used for buttons in the activitypointer at the subgrid level. This code only works in UCI, in Classic it shows a 'does nothing' behavior from a user's perspective, performing the action with the console open throws the following crash report:
    CrashReport:
            FileName:/userdefined/areas.aspx
            LineNumber:0
            Function:OpenNewActivityFromMain
            ErrorReport:<CrmScriptErrorReport>
      <ReportVersion>1.0</ReportVersion>
       <OriginContext>XMLHandler</OriginContext>
       <OriginCorrelationId>{18633321-180d-587b-b50a-5d1da5a09911}</OriginCorrelationId>
      <ScriptErrorDetails>
       <Message>Cannot read property &#39;entity&#39; of undefined</Message>
       <ExceptionNumber>0</ExceptionNumber>
       <Line>0</Line>
       <URL>&#47;userdefined&#47;areas.aspx&#63;formid&#61;1fed44d1-ae68-4a41-bd2b-f13acac4acfa&#38;inlineEdit&#61;1&#38;navItemName&#61;Activities&#38;oId&#61;&#37;&#37;7d&#38;oType&#61;2&#38;pagemode&#61;iframe&#38;rof&#61;true&#38;security&#61;&#38;tabSet&#61;areaActivities&#38;theme&#61;Outlook15White</URL>
       <PageURL>&#47;userdefined&#47;areas.aspx&#63;formid&#61;1fed44d1-ae68-4a41-bd2b-f13acac4acfa&#38;inlineEdit&#61;1&#38;navItemName&#61;Activities&#38;oId&#61;&#37;&#37;7d&#38;oType&#61;2&#38;pagemode&#61;iframe&#38;rof&#61;true&#38;security&#61;&#38;tabSet&#61;areaActivities&#38;theme&#61;Outlook15White</PageURL>
       <Function>OpenNewActivityFromMain</Function>
       <FunctionRaw></FunctionRaw>
       <SourceScriptName>&#36;webresource&#58;prefix_&#47;Library&#47;FILENAME.js</SourceScriptName>
       <CallStack>
    TypeError&#58; Cannot read property &#39;entity&#39; of undefined&#10;    
    at OpenNewActivityFromMain &#40;&#60;anonymous&#62;&#58;374&#58;45&#41;&#10;    
    at Function.Mscrm.Utilities.executeJavascriptFunction &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_common&#47;global.ashx&#63;ver&#61;1827875685&#58;6872&#58;600137&#41;&#10;    
    at Mscrm.CommandHandler.&#36;Cu_1 &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;82809&#41;&#10;    
    at Mscrm.CommandHandler.&#36;Ap_1 &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;82149&#41;&#10;    
    at Mscrm.CommandHandler.handleCommand &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;77060&#41;&#10;    
    at Mscrm.CommandBarData.executeCommand &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;146505&#41;&#10;    
    at Mscrm.ButtonControl.executeCommand &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;60024&#41;&#10;    
    at Mscrm.ButtonControl.click &#40;https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;56109&#41;&#10;    
    at https&#58;&#47;&#47;orgname.crm.dynamics.com&#47;_static&#47;_controls&#47;ribbon&#47;ribbon.js&#63;ver&#61;1827875685&#58;1&#58;16134   </CallStack>
      </ScriptErrorDetails>
      <ClientInformation>
       <BrowserUserAgent>Mozilla&#47;5.0 &#40;Windows NT 10.0&#59; WOW64&#41; AppleWebKit&#47;537.36 &#40;KHTML, like Gecko&#41; Chrome&#47;80.0.3987.122 Safari&#47;537.36</BrowserUserAgent>
       <BrowserLanguage>undefined</BrowserLanguage>
       <SystemLanguage>undefined</SystemLanguage>
       <UserLanguage>undefined</UserLanguage>
       <ScreenResolution>1920x1080</ScreenResolution>
       <ClientName>Web</ClientName>
       <ClienState>Online</ClienState>
       <ClientTime>2020-03-04T13&#58;19&#58;32</ClientTime>
      </ClientInformation>
    </CrmScriptErrorReport>

    It seems I'm unable to access primaryControl from the associated view on classic? Is there a way to make this code work for both interfaces?

    Thank you.

    ------------------------------
    Eli Rodriguez
    Systems Engineer
    WI
    ------------------------------


  • 2.  RE: Custom Button does nothing in Classic, Works in UCI

    SILVER CONTRIBUTOR
    Posted 24 days ago
    Hi Eli,

    Add an alert(itemReference); and see what it is throwing in UCI vs in the classic.

    ------------------------------
    Cristall Amurao
    Tala Dynamics
    North York
    ------------------------------



  • 3.  RE: Custom Button does nothing in Classic, Works in UCI

    SILVER CONTRIBUTOR
    Posted 23 days ago
    Hi @Lyrio Amurao

    Its not throwing anything in Classic, the code cannot access the entity property of the data on a form. It only happens on associated entity view of a record, and only in classic. In UCI this code is working without issues.

    ------------------------------
    Eli Rodriguez
    Systems Engineer
    WI
    ------------------------------



  • 4.  RE: Custom Button does nothing in Classic, Works in UCI

    SILVER CONTRIBUTOR
    Posted 22 days ago
    Hi Eli,

    Based on the error message, it looks like it cannot get its value.

    I have not worked on the classic UI in a while since we are introducing everyone to UCI. Try debugging to see if it has value.

    function OpenNewActivityFromMain(primaryControl) {
    debugger;
    var formContext = primaryControl;

    try {
    var entityFormOptions = {};
    var parameters = {};
    var itemReference = formContext.data.entity.getEntityReference();

    entityFormOptions["entityName"] = entityLogicalName;
    entityFormOptions["createFromEntity"] = {
    entityType: itemReference.entityType,
    id: itemReference.id,
    name: itemReference.name
    };

    Xrm.Navigation.openForm(entityFormOptions, parameters);

    } catch (e) {
    alert(e.message);
    }
    }

    ------------------------------
    Lyrio Amurao
    Tala Dynamics
    North York
    ------------------------------



  • 5.  RE: Custom Button does nothing in Classic, Works in UCI

    SILVER CONTRIBUTOR
    Posted 20 days ago
    Hi @Lyrio Amurao this is correct, when on classic primaryControl returns undefined. I wonder if its because you navigate away from the Main Form of the entity. I need to find a way to get the formContext from the associated view in classic. ​

    ------------------------------
    Eli Rodriguez
    Systems Engineer
    WI
    ------------------------------



If you've found this thread useful, dive deeper into User Group community content by role