Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

Posted on by Microsoft Employee

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

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    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.

  • Suggested answer
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    HI Ezgi,

    Are you still getting the same error?

    Make sure that toID which ur setting is available in Account entity.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    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.

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    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" }])

  • Suggested answer
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    Hi Gopalan,

    When I debug it, it returns the toId and I already have a control on top of my second function (setMusteriDetails).

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Cannot read property 'trim' of undefined on PhoneCall Form while setting another field with "to"

    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" }])

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans