Search code examples
javascriptdynamics-crmdynamics-crm-online

Create static URL hyperlink in Dynamics CRM form via JavaScript


I would like to create a field on a form that users can click on to reference a sharepoint file that is in a static location. I created a script and added it to the page but I'm getting an error message. Can anyone please help?

Script:

function createUrl () {
    var VersionSpreadsheet = "https://mycompany.sharepoint.com";
    Xrm.Page.data.entity.attributes.get("new_VersionSpreadsheet").setValue(VersionSpreadsheet);
}

Error:

One of the scripts for this record has caused an error. For more details, download the log file. TypeError: Cannot read property 'setValue' of null at createUrl


Solution

  • The attribute names are case sensitive and it should be all lowercase. Also the shortcut and crisp version is below.

    function createUrl () {
        var VersionSpreadsheet = "https://mycompany.sharepoint.com";
        Xrm.Page.getAttribute("new_versionspreadsheet").setValue(VersionSpreadsheet);
    }