Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

CRM 2011 Function to copy contents of Contact lookup to Name primary field of custom entity

$
0
0

OK I have been struggling with this stupid problem for 3 days and am going to ask for help. To preface this, I am (obviously) not a Javascript expert...or even amateur. My knowledge is pretty limited. However, I don't have a backup and have to figure this out.

So I am trying to accomplish what i thought would be a very simple and common task. I have a custom entity called Resumes. I would like the primary key/name field (new_name is field name) to be populated with lookup data from the Contact entity (new_applicantname is field name). Because this seems like a common scenario, I was surprised that all the solutions I found so far present something much more complicated than what I think I need - ie: they add time/date to name, they work with arrays and option sets, they slice bread, etc. I want to simply copy the contents of one field to another.

I need this to work on Resume creation/onload, and if/when Resume is changed/onsave.

I found the script below which works onload in IE, but not in Chrome. It also works onsave in both IE and Chrome.

The problem is that it concatenates the date/time, which I don't want. I need the REsume name to match exactly with the Contact lookup name.


function SetName(){
var lookupField = Xrm.Page.getAttribute("new_applicantname");

// Retrieve the Current Date

var Now = new Date();

// Convert the Date to a String

var StringNow = Now.toString();

// Set the Name

Xrm.Page.getAttribute("new_name").setValue(lookupField.getValue()[0].name + "-" + StringNow);
}


I made changes to the script to come up with what i thought would be the logical, and much simplified solution, as follows:

function SetName()
{
var lookupField = Xrm.Page.getAttribute("new_applicantname");
Xrm.Page.getAttribute("new_name").setValue(lookupField);
}

But it doesn't work. In both IE/Chrome, onload it says "This control only accepts strings or null as an input". Is there something simple that I'm missing here? Or should I just do this via a workflow? Am I missing some kind of error handling, or do I need to pre-populate the field with a null variable before I copy the lookup data to it?

Thank you in advance for any ideas/input.
-Daniel

BONUS POINTS: Also, anyone know why Chrome would run script above onsave but not onload?


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>