web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Navigation link with custom URL

(0) ShareShare
ReportReport
Posted on by 925

Hello,

On the Account form, I need a Navigation Link (left) with a dynamic URL with the Lead's email address as part of the URL.

I'm only able to catch the GUID of the account but not other fields.

I have followed this tutorial (www.crmanswers.net/.../dynamic-navigation-links-using.html) and created a HTML Web Resource.

Script seems to fail at the "$.ajax({" part:

<HTML><HEAD>

<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx" script></SCRIPT>

<SCRIPT type=text/javascript src="code.jquery.com/.../SCRIPT>

<SCRIPT language=javascript>

function GoToDynamicUrl(accountName) {

  var dynamicUrl = "www.bing.com/search + accountName;

  location.href = dynamicUrl;

}

function getURLParameter(name) {

  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;

}

function retrieveRecord(id, odataSetName, successCallback, errorCallback) {

  var context = Xrm.Page.context;

  var serverUrl = context.getServerUrl();

  var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

  $.ajax({

     type: "GET",

     contentType: "application/json; charset=utf-8",

     datatype: "json",

     url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",

     beforeSend: function (XMLHttpRequest) {            

        XMLHttpRequest.setRequestHeader("Accept", "application/json");

     },

     success: function (data, textStatus, XmlHttpRequest) {

        if (successCallback) { successCallback(data.d); }

     },

     error: function (XmlHttpRequest, textStatus, errorThrown) {

        if (errorCallback) { errorCallback(errorThrown); }

     }

  });

}

function retrieveSuccess(data) {

  // we call the GoToDynamicUrl function with the Account Name

  alert(data.Name);

  GoToDynamicUrl(data.Name);

}

function retrieveError(error) {

  alert("Error: " + error);

}

</SCRIPT>

<META charset=utf-8></HEAD>

<BODY contentEditable=true>

<SCRIPT language=javascript>

// Retrieve the id from the query string

var id = getURLParameter('id');

// Retrieve the record and call the success function

retrieveRecord(id, 'AccountSet', retrieveSuccess, retrieveError);

</SCRIPT>

</BODY></HTML>

*This post is locked for comments

I have the same question (0)
  • Kitco Profile Picture
    925 on at

    When lauching URL built on a separate browser, it works but when calling it thru ajax, it fails.

    Any help would be greatly appreciated

  • Suggested answer
    Nizar JLASSI Profile Picture
    2 on at

    Hi Kitco,

    Try to use available javascript librairies that allow you to access to your data with the easiest way.

    You can use XrmServiceToolkit on CodePlex. It allow you to use REST or SOAP protocols with Async or Sync. 

    In your example, you can use retrieveRecord  function.

    If you are not obliged to use ODATA, you can use XrmServiceToolkit SOAP libraiy like this:

    1. var queryOptions = {
    2.     entityName: "account",
    3.     attributes: ["accountid"],
    4.     values: [yourAccountId],
    5.     columnSet: ["name"]
    6. };
    7.  
    8. var fetchedAccount = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);
    9. if (fetchedAccount.length >= 0) {
    10.     // You can use this way
    11.     var accountName = fetchedAccount[0].attributes["name"].value;
    12.     // Or this way
    13.     var accountName = fetchedAccount[0].attributes.name;
    14. }

    I hope that it can help you.

    Nizar JLASSI
    Dymamics CRM Trainer and Senior Consultant
    Email : n.jlassi@gmail.com

             

  • Kitco Profile Picture
    925 on at

    Sorry if my question is dumb but I downloaded the package but where do I put it?

    On the CRM server? Which folder path?

    Thanks again

  • Suggested answer
    Nizar JLASSI Profile Picture
    2 on at

    You need to verify witch CRM version you use (there is 1.4 for CRM 2011 and 2.0 for CRM 2013)

    After that you download it and you extract it in a folder.

    It contains 3 files (jquery.js, json2.js and XrmServiceToolkit.js)

    You need to add them as webresources in your Crm Solution.

    N.B: If you have jquery librairy or Json librairy in your CRM, you don't need to add them and I should only add the XrmServiceToolkit.js.

    After that on you HTML Web Resource you add these lines :

    1. <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
    2. <script type="text/javascript" src="new_json2.js"></script>
    3. <script type="text/javascript" src="new_jquery.js"></script>
    4. <script type="text/javascript" src="new_XrmServiceToolkit.js"></script>

    Be Careful, if your web resources has another names, you should to put the right names on scripts tags.

    and Finally, you put your javascript code in your <script></script> tag

    Nizar JLASSI
    Dymamics CRM Trainer and Senior Consultant
    Email : n.jlassi@gmail.com

    4TOCOPWZQ6TL.jpg  4TOCOSXBT5KL.jpg  4TOOJYT41KG6.jpg  

  • Kitco Profile Picture
    925 on at

    Hello,

    I have done what you said but the call fails at:

    var fetchedAccount = XrmServiceToolkit.Soap.QueryByAttribute(queryOptions);

    it does nothing

    I placed an alert statement to view the content of queryOptions and it set it correctly, however the call doesn't do anything.

    Any way to debug or put some sort of try catch functionality?

  • Kitco Profile Picture
    925 on at

    I am running CRM 2011 so I downloaded package: XrmServiceToolkit 1.4.1 for CRM 2011

  • Nizar JLASSI Profile Picture
    2 on at

    To debug in IE, use F12 key .

    If you are using IE 11, when you push F12 key: a window will appear, you should click on debugger bouton.

    2844.F12_2D00_3.PNG

    You can search XrmServiceToolkit and QueryByAttribute in search input

    4TOCONT325S9.jpg

    It will open the XrmServiceToolkit.js file

    4TOCOPWZQ6TL.jpg

    And you can put breakpoints and debug your code.

    Nizar JLASSI

    4TOCOSXBT5KL.jpg  4TOOJYT41KG6.jpg     

  • Kitco Profile Picture
    925 on at

    Ok,

    Error shows that:

    XrmServiceToolkit is undefined:

  • Kitco Profile Picture
    925 on at

    Here are the 3 web resources 

    2553.Calling3Javascripts.png

    and here is the call

  • Nizar JLASSI Profile Picture
    2 on at

    Hi Kitco,

    To works fine, <script></script> tags should be inside <head></head> tags not inside <body></body> tags.

    Another point, did you add there files in event tab in your form properties ?


    Nizar JLASSI
    Dymamics CRM Trainer and Senior Consultant
    Email : n.jlassi@gmail.com

    4TOCOPWZQ6TL.jpg  4TOCOSXBT5KL.jpg  4TOOJYT41KG6.jpg  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans