Thursday, May 5, 2016

Convert Text field to URL Field MSCRM 2013/2015/2016

Hi All,

Please find the Below code to Convert Text field to URL Field.

In My case, if user selects a look up value, In onsave operation am saving the value as to the text field as AccountName*AccountnameGuid (initially make the Lookup field enable and make the text field disable)

Once the save operation done. In onload make the Lookup field disable and show the Custom Text to Url Field.

Copy paste the below code and pass the value to "fieldname" to make the value display properly.

After onsave take field should save like below format




After onload the text field will display like below URL Field



function onload(){
converttexttoURL("fieldname");
}

 
function onsave(){
var fldLink = Xrm.Page.data.entity.attributes.get("fieldname");
if (fldLink) {

fldLink.setValue(fldIntroducedTo.getValue()[0].name + "*" + fldIntroducedTo.getValue()[0].id);

fldLink.setSubmitMode("always");
}



function converttexttoURL(fldName) {try {
var getLinkfromTextField = Xrm.Page.data.entity.attributes.get(fldName);

if (getLinkfromTextField && getLinkfromTextField.getValue()) {

var getdatafromfield = fldLink.getValue();

var btnHTML = "<a href='javascript: void(0);' title='" + getdatafromfield.split('*')[0] + "' onclick=\"openAccount('" + getdatafromfield.split('*')[1] + "')\" style='color:blue;text-decoration:underline !important'>" + getdatafromfield.split('*')[0] + "</a>";

var getFieldControl = document.getElementById(fldName);
if (getFieldControl) {

// Set the new HTML to the field
getFieldControl.innerHTML = btnHTML;}
 
// Show Link field

Xrm.Page.ui.controls.get(fldName).setVisible(true);

}
 
} catch (e) {

alert("Error in convertourl- " + e.description);
}
}


function openAccount(accountId) {

if (Xrm && Xrm.Utility && accountId) {

Xrm.Utility.openEntityForm('account', accountId);
}
}
 
 

No comments:

Post a Comment

How to Import Data from Excel to Multiple tables in PowerApps

Introduction:   I have created a view on how to import data from excel to multiple tables in Canvas PowerApps   Implemented Steps: ...