Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Script error on mobile app, doesn't occur on browser

Posted on by 65

Hi,

I encountered an error on mobile version of CRM:

TypeError: Cannot read property 'text' of null

It is caused by following line of code:

var statusofsell = Xrm.Page.getControl("header_process_statusofsell").getAttribute().getText();

"statusofsell" is a field on business process flow.

It doesn't occur on browser. (version 9)

I will be grateful for any suggestions!

*This post is locked for comments

  • Pocia Profile Picture
    Pocia 65 on at
    RE: Script error on mobile app, doesn't occur on browser

    Thank you, this worked.

    And thank you all for your help!

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Script error on mobile app, doesn't occur on browser

    I have no idea what's wrong but following should make your code work:

    1. Put this field to form and make it hidden.

    2. Change your code to following:

    var statusofsell = Xrm.Page.getAttribute("statusofsell").getText();

    According to this article - msdn.microsoft.com/.../gg334409.aspx it should work but if you keep getting errors try following:

    var statusofsell = Xrm.Page.getAttribute("statusofsell").getValue() == null ? "" : Xrm.Page.getAttribute("statusofsell").getText();

  • Pocia Profile Picture
    Pocia 65 on at
    RE: Script error on mobile app, doesn't occur on browser

    a33ik

    Field schema name: statusofsell

    Screenshots:

    1. Web version of business process flow:

    6470.bpf2.jpg

    2. Mobile version of business process flow:

    6470.bpf2.jpg

    Field label: Status of this sell

    Note that script error pops up only when field is empty- when it contains data, everything works well.

  • NODAL Profile Picture
    NODAL 860 on at
    RE: Script error on mobile app, doesn't occur on browser

    Hi Pocia,

    I had a similar issue.

    And the reason was the same field having different schema name in web and uci.

    Follow following steps

    1)open record in web chrome do f12 and check schema of that field.

    2) open same entity record in chrome uci format pop out bpf fields collection. Check schema name i.e. Id.

    3) the they are different while writting first check null for both schema and put value in a variable.

    Var name;

    If(formContext.getControl(webschemaname)!==null)

    {name=

    formContext.getControl(webschemaname).getValue()}

    If(formContext.getControl(ucischemaname)!==null)

    {name=formContext.getControl(ucischema).getValue()}

    Regards,

    ND

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Script error on mobile app, doesn't occur on browser

    Can you please provide a screenshot of your form and schema name of field behind "header_process_statusofsell" control?

  • Pocia Profile Picture
    Pocia 65 on at
    RE: Script error on mobile app, doesn't occur on browser

    Thanks for suggestion Andrew.

    However, now the error has changed to TypeError: Cannot read property 'getAttribute' of null

    //edit: double checked, and it's the same error as it was at the beginning :(

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Script error on mobile app, doesn't occur on browser

    Try to use following:

    var statusofsell = Xrm.Page.getControl("header_process_statusofsell").getAttribute().getValue() == null ? "" : Xrm.Page.getControl("header_process_statusofsell").getAttribute().getText();

  • Pocia Profile Picture
    Pocia 65 on at
    RE: Script error on mobile app, doesn't occur on browser

    Thank you, Oleksandr.

    Unfortunately, changing Xrm.Page, to formContext didn't help.

    I may add, that when field "status of sell" is filled, the error doesn't occur. Maybe it's a problem with getting text from an empty field?

    The script is executed OnLoad.

  • Suggested answer
    Psyionic Profile Picture
    Psyionic 195 on at
    RE: Script error on mobile app, doesn't occur on browser

    Hi Pocia,

    This is because mobile version of CRM using new UCI interface, which doesn't support Xrm.Page object model. Please use formContext instead of Xrm.Page to be able to use getText in new interface. You can find more about using new client side API model here and about using formContext with getText() function here.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans