xrmservicetoolkit is undefined

May 27, 2013 at 3:58 PM
I have downloaed the toolkit as well as the solution. I have installed the solution I have tried everything I can to get this to work.

Background:

I have a js that gets called when I click an icon on the ribbon bar. What I want to do is take a hand full of fields from this entity and add a record to the new entity. As soon as I turn debugging on I get xrmservicetoolkit is undefined. There is no html involved so I can't include script tags.

Thanks in advance for any help you can provide.

// Covert Lot to Great Car
/// <reference path="ISV/CRMServiceToolkit/XrmServiceToolkit.js" />

function addgreat() {
var year = Xrm.Page.data.entity.attributes.get("esi_year").getValue();

// Here is where I get the undefined.
    var beGreatCar = XrmServiceToolkit.Soap.businessEntity("esi_car");

 beGreatCar.attributes["esi_year"] = Xrm.Page.data.entity.attributes.get("esi_year").getValue();
    beGreatCar.attributes["esi_make"] = Xrm.Page.data.entity.attributes.get("esi_make").getValue();
    beGreatCar.attributes["esi_model"] = Xrm.Page.data.entity.attributes.get("esi_model").getValue();
    beGreatCar.attributes["esi_chassissnumber"] = Xrm.Page.data.entity.attributes.get("esi_chassisnumber").getValue();
    beGreatCar.attributes["esi_enginenumber"] = Xrm.Page.data.entity.attributes.get("esi_enginenumber").getValue();
    beGreatCar.attributes["esi_bodystyle"] = Xrm.Page.data.entity.attributes.get("esi_bodystyle").getValue();
    beGreatCar.attributes["esi_coachworkby"] = Xrm.Page.data.entity.attributes.get("esi_bodyby").getValue();
    beGreatCar.attributes["esi_bodynumber"] = Xrm.Page.data.entity.attributes.get("esi_bodynumber").getValue();

    // Check for last know owner. Make it the buyer unless that is blank then make it the seller

    if (Xrm.Page.data.entity.attributes.get("esi_bidregbuyerid").getValue() != null) {
        beGreatCar.attributes["esi_contactid"] = Xrm.Page.data.entity.attributes.get("esi_bidregbuyerid").getValue();
    } else {

       beGreatCar.attributes["esi_contactid"] = Xrm.Page.data.entity.attributes.get("esi_sellerid").getValue();
    };

    oService.Create(beGreatCar);
    alert(year + " Added to Great Cars.");        
    }
May 29, 2013 at 12:53 PM
For anyone looking at the same error.

I figured out my issue on this. I had added it to my solution but not to my form. Once I added it to the form I was able to get to my next error.
Coordinator
Jun 2, 2013 at 10:42 AM
Edited Jun 2, 2013 at 10:56 AM
Hi There.

When calling external functions from third party library from CRM ribbon button, you will need to have the JavaScript file loaded from ribbon first. If the third party library which contains the function you called also depends on other libraries like JSON2, jQuery, Xrmserivetoolkit, you will also have to load them first.

For you case, ribbon customization may be something like the code below
<Actions>
    <JavaScriptFunction FunctionName="isNaN" Library="$webresource:new_json2" />
    <JavaScriptFunction FunctionName="isNaN" Library="$webresource:new_jquery" />
    <JavaScriptFunction FunctionName="isNaN" Library="$webresource:new_XrmServiceToolkit" />
    <JavaScriptFunction FunctionName="addgreat" Library="$webresource:new_ribbon">
    <CrmParameter Value="SelectedEntityTypeName" />
    <CrmParameter Value="FirstSelectedItemId" />
    </JavaScriptFunction>
</Actions>