Hi all,
I am trying to set a lookup(account) field with "to" field on phonecall form. But while setting it I get this following error message.
"TypeError: Cannot read property 'trim' of undefined
at Function.Number._parse (crm.arvento.com/.../global.ashx)
at Function.Number.parseInvariant (crm.arvento.com/.../global.ashx)
at Mscrm.TurboForm.Control.ViewModel.QuickFormViewModel.$Gh_4 (crm.arvento.com/.../formcontrols.js)
at crm.arvento.com/.../global.ashx
at crm.arvento.com/.../global.ashx
at Mscrm.TurboForm.Control.Data.LookupDataAttribute.fireOnChangeInternal (crm.arvento.com/.../formcontrols.js)
at Mscrm.TurboForm.Control.Data.LookupDataAttribute.setValueInternal (crm.arvento.com/.../formcontrols.js)
at Mscrm.TurboForm.Control.Data.LookupDataAttribute.setValue (crm.arvento.com/.../formcontrols.js)
at Mscrm.FormControls.ClientApi.XrmTurboFormEntityAttributeLookup.setValue (crm.arvento.com/.../formcontrols.js)
at setMusteriDetails (crm.arvento.com/.../new_telefonGorusmesi)"
and here is my js code;
function ToOnChange(){ var to = Xrm.Page.getAttribute("to").getValue(); if (to != null) { if (to[0] != undefined) { if (to[0].entityType == "account") { var toId= to[0].id.toString().replace("{", "").replace("}", ""); setMusteriDetails(toId); } } } } function setMusteriDetails(toId) { if (toId!= null) { //retrieve musteri detail var queryMusteri = "accounts(" + toId+ ")?$select=emailaddress1,_new_bayi_value,_new_bolge_value,_new_sehir_value,_new_ulke_value,name"; var resultMusteri = RestBuilder("GET", queryMusteri); var emailAddress = resultMusteri["emailaddress1"]; var bayiId = resultMusteri["_new_bayi_value"]; var bayiAdi = resultMusteri["_new_bayi_value@OData.Community.Display.V1.FormattedValue"]; var bolgeId = resultMusteri["_new_bolge_value"]; var bolgeAdi = resultMusteri["_new_bolge_value@OData.Community.Display.V1.FormattedValue"]; var sehirId = resultMusteri["_new_sehir_value"]; var sehirAdi = resultMusteri["_new_sehir_value@OData.Community.Display.V1.FormattedValue"]; var ulkeId = resultMusteri["_new_ulke_value"]; var ulkeAdi = resultMusteri["_new_ulke_value@OData.Community.Display.V1.FormattedValue"]; var toName= resultMusteri["name"]; //set musteri detail Xrm.Page.getAttribute("new_email").setSubmitMode("always"); Xrm.Page.getAttribute("new_email").setValue(emailAddress); Xrm.Page.getAttribute("new_bayi").setSubmitMode("always"); Xrm.Page.getAttribute("new_bayi").setValue([{ id: bayiId, name: bayiAdi, entityType: "new_bayi" }]); Xrm.Page.getAttribute("new_bolge").setSubmitMode("always"); Xrm.Page.getAttribute("new_bolge").setValue([{ id: bolgeId, name: bolgeAdi, entityType: "new_bolge" }]); Xrm.Page.getAttribute("new_sehir").setSubmitMode("always"); Xrm.Page.getAttribute("new_sehir").setValue([{ id: sehirId, name: sehirAdi, entityType: "new_sehir" }]); Xrm.Page.getAttribute("new_ulke").setSubmitMode("always"); Xrm.Page.getAttribute("new_ulke").setValue([{ id: ulkeId, name: ulkeAdi, entityType: "new_ulke" }]); Xrm.Page.getAttribute("new_musteri").setSubmitMode("always"); Xrm.Page.getAttribute("new_musteri").setValue([{ id: toId, name: toName, entityType: "account" }]); //set bayi telefon var queryBayi = "new_bayis(" + bayiId + ")?$select=new_tel"; var resultBayi = RestBuilder("GET", queryBayi); var bayiTel = resultBayi["new_tel"]; if (bayiTel != null) { Xrm.Page.getAttribute("new_bayitelefon").setValue(bayiTel); } } }
It works fine if I delete the code sets new_musteri field. I wonder why I get that error.
I really appreciate any help.
Thanks!
*This post is locked for comments
I have created a new lookup(account) filed but with a different name than new_musteri and now it works fine.
Thank you all for taking the time to help me.
HI Ezgi,
Are you still getting the same error?
Make sure that toID which ur setting is available in Account entity.
Hi Lakshmisha,
I controlled it again but no luck. Btw it sets the field but still pops up this error. I feel like it might be bc you can pick more than one record for to field on phonecall form but I have no idea how to prevent it.
You are using account lookup field new_musteri in the phonecall form.
Please check the value of toName.
Try hard coded values for toId, toName in the following
Xrm.Page.getAttribute("new_musteri").setValue([{ id: toId, name: toName, entityType: "account" }])
Hi Ezgi,
I think your not able to find the control "new_musteri" in your form. make sure that this field exist in the form and it is named correctly. And its not set as hidden.
To avoid the error its always a best practice to use the null check before assigning value to any control.
Mark as Answer if it helps you.
Hi Gopalan,
When I debug it, it returns the toId and I already have a control on top of my second function (setMusteriDetails).
Hi
Looks like toId is null.
Check for the value for toId, while debugging.
Add a condition similar to
if(toId != null)
{
Xrm.Page.getAttribute("new_musteri").setSubmitMode("always");
Xrm.Page.getAttribute("new_musteri").setValue([{ id: toId, name: toName, entityType: "account" }])
}
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,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156