1
votes

I have an entity called Customer Site from which I store Site information. From this site I create devices (another custom entity). I have created relevent address fields to those of the address entity in my customer site entity and I am trying to (based on an account) fill my site fields with those of a selected address from the account.

I referred to this article for doing so, http://xrmexpertz.com/2012/01/24/lookup-address-for-custom-entities-in-crm-2011/

I've altered the javascript and xml provided in the link to reflect my entities and my web resource.

My problem is that when i click the button that should execute the JavaScript it does nothing, and if I try to save a site without a account it sends me and error.

this is my java script.

function CustomLookup() {
'use strict';
var aoItems = getFieldValue("kez_SiteInfo_AccountId");

if (aoItems == null) {

    alert(“Account is not Selected”);

    return;

}

var _object = openStdDlg(“ / sfa / quotes / dlg_lookupaddress.aspx ? headerForm = 1 & parentType = 1 & parentId = ” + aoItems[0].id + “ & willCall = 0″, “LookupAddress”, 500, 330, true);

if (object) {

    setFieldValue(“kez_address1_name”, object.Address.Name);

    setFieldValue(“kez_address1_line1″, object.Address.Line1);

    setFieldValue(“kez_address1_line2″, object.Address.Line2);

    setFieldValue(“kez_address1_line3″, object.Address.Line3);

    setFieldValue(“kez_address1_city”, object.Address.City);

    setFieldValue(“kez_address1_province”, object.Address.StateOrProvince);

    setFieldValue(“kez_address1_postalcode”, object.Address.PostalCode);

    setFieldValue(“kez_address1_country”, object.Address.Country);

}

}

function setFieldValue(fieldName, fieldValue) {

Xrm.Page.getAttribute(fieldName).setValue(fieldValue);

}

This is the error is gives

Microsoft Dynamics CRM Error Report Contents

<CrmScriptErrorReport>
  <ReportVersion>1.0</ReportVersion>
  <ScriptErrorDetails>
   <Message>Uncaught SyntaxError: Unexpected token ILLEGAL</Message>
   <Line>7</Line>
   <URL>/%7B634962800260003236%7D/WebResources/kez_GetLocation</URL>
   <PageURL>/userdefined/edit.aspx?_gridType=10018&etc=10018&id=%7b1F8E02F0-766C-E211-934E-   00155D018211%7d&pagemode=iframe&preloadcache=1360684076423&rskey=69426415</PageURL>
   <Function></Function>
   <CallStack>
   </CallStack>
  </ScriptErrorDetails>
  <ClientInformation>
   <BrowserUserAgent>Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.30 (KHTML, like Gecko)       Chrome/26.0.1403.0 Safari/537.30</BrowserUserAgent>
   <BrowserLanguage>undefined</BrowserLanguage>
   <SystemLanguage>undefined</SystemLanguage>
   <UserLanguage>undefined</UserLanguage>
   <ScreenResolution>1366x768</ScreenResolution>
   <ClientName>Web</ClientName>
   <ClientTime>2013-02-12T10:47:58</ClientTime>
  </ClientInformation>
  <ServerInformation>
    <OrgLanguage>1033</OrgLanguage>
    <OrgCulture>1033</OrgCulture>
    <UserLanguage>1033</UserLanguage>
    <UserCulture>1033</UserCulture>
    <OrgID>{BC278BC1-EEEA-4D24-B5C6-F0720B343A1F}</OrgID>
    <UserID>{D76EEA89-D760-E211-921F-00155D018211}</UserID>
    <CRMVersion>5.0.9690.3236</CRMVersion>
  </ServerInformation>
</CrmScriptErrorReport>
1
What is on line 7 of the WebResource called kez_GetLocation?glosrob
Is kez_GetLocation some JS that's causing issues here?Konrad Viltersten
I found the problem but at the moment i can't answer my own question. To answer the fist comment, line 7 throws an error because the quotes used in the link I provided were not recognized by CRM so I just removed and readded them and it fixed that.Aaron
kez_GetLocation is the JS i provided above with the function CustomLookup.Aaron
As of right now the code is working perfectly, when I can i'll upload the final working code and answer the question.Aaron

1 Answers

0
votes

I ended up solving the problem, for one the source i listed uses quotes not recognized by CRM. Next I had to use XRM.getAttribute instead of getFieldValue.

The final and working code is below:

function CustomLookup() {
'use strict';
var aoItems = Xrm.Page.getAttribute('kez_siteinfo_accountid').getValue();
if (aoItems == null) {

    alert("Account is not Selected");

    return;

}

var _object = openStdDlg("/sfa/quotes/dlg_lookupaddress.aspx?headerForm=1&parentType=1&parentId=" + aoItems[0].id + "&willCall=0", "LookupAddress", 500, 330, true);

    if (object) {

    setFieldValue("kez_address1_name", object.Address.Name);

    setFieldValue("kez_address1_line1", object.Address.Line1);

    setFieldValue("kez_address1_line2", object.Address.Line2);

    setFieldValue("kez_address1_line3", object.Address.Line3);

        setFieldValue("kez_address1_city", object.Address.City);

        setFieldValue("kez_address1_province", object.Address.StateOrProvince);

        setFieldValue("kez_address1_postalcode", object.Address.PostalCode);

        setFieldValue("kez_address1_country", object.Address.Country);

    }

}

function setFieldValue(fieldName, fieldValue) {

    Xrm.Page.getAttribute(fieldName).setValue(fieldValue);

}