When a search doesn't shows results I want to take this text and put on First Name and Last Name on a New Quick Contact
Is possible?
Thanks
When a search doesn't shows results I want to take this text and put on First Name and Last Name on a New Quick Contact
Is possible?
Thanks
Hi Ravi thanks for your help, I change the code and it works fine, I wonder if you would like to give me just your opinion of this problem that I dont have any idea how to solve without changing all my unique code for my clients..
More details...
community.dynamics.com/.../957111
Thank you.
------------------------------------------
function loadsearchResults() {
try {
var searchResults = Xrm.Page.getAttribute("lastname").getValue();
var searchName = searchResults.split(" ");
Xrm.Page.getAttribute("new_primernombre").setValue(searchName[0]);
Xrm.Page.getAttribute("new_primerapellido").setValue(searchName[1]);
Xrm.Page.getAttribute("lastname").setValue(searchName[1]);
}
catch (err) {
console.log(err.message);
}
}
The logic seems correct. If you remember, CRM automatically puts the value in the last name field. So you need to run this code on Contact On Load, get the value from the last name field, split the value and then set it as per your requirement.
By the way, do you have your custom field for firstname and last name because contact field name are firstname & lastname
Hi Ravi,
I made this code, and doesn't do anything when I create a new contact, I load it onLoad form of Quick Contact, sorry I new on JS
"new_contacto" is the lookup field of Contact on the main form, in this field is where I search the name and last name.
"new_primernombre" is the field in Contacts entity where I want to paste the "First Name" value.
"new_primeapellido" is the field in Contacts entity where I want to paste the "First of Last Name" value
function loadsearchResults() {
try {
var searchResults = window.top.frames[0].Xrm.Page.getAttribute("new_contacto").getValue();
var searchName = searchResults.split(" ");
Xrm.Page.getAttribute("new_primernombre").setValue(searchName[0]);
Xrm.Page.getAttribute("new_primerapellido").setValue(searchName[1]);
}
catch (err) {
console.log(err.message);
}
}
Thanks
As mentioned above, you can add a JS code on load to split based on either of the option specified above i.e split and put last as last name or split and put first as first name.
Let me know what you want and I will see if I code share any sample code with you.
Hi Ravi
In the case the name is just Ravi Kashyap, one name and one last name. how I can do it in javascript ?
Take the value what I am searching and slipt this value on a new quick contact.
Thanks
Hi,
It happens automatically however it puts the full text into last name field. As it is not easy to separate first name & last name logically i.e. If the name is Ravi Kumar Kashyap, you would not know if Ravi needs to go to first name or Ravi Kumar.
However if you decide and confirmed the name split approach like
1) Take the first bit i.e. before space, put in in first name and put everything else on the last name. Or
2) Take the last bit i.e. after last space, put in in last name and put everything else on the first name.
Then you can add a JavaScript code on the load of your contact which checks if the form is create and last name contains data, then split the name and put it based on any of the above logic.
Hope this helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156