Skip to main content

Notifications

Dynamics 365 general forum

JS code error on UI client but not on web client

Posted on by Microsoft Employee

Hi everyone 

I'm getting following error from custom ribbon button: 

"Unable to get property 'getFormContext' of undefined or null reference"

js code:

var Sdk = window.Sdk || {};
(function () {

this.startclock = function (executionContext) {
var formContext = executionContext.getFormContext();
var triggervalue = formContext.getAttribute("acc1_startclocktrigger");
var notice = formContext.getAttribute("acc1_wfnotice");
var oldvalue = triggervalue.getValue();
var newvalue = ++oldvalue;
triggervalue.setValue(newvalue);
notice.setValue("0");
formContext.data.entity.save();
}

}).call(Sdk);

Any ideas?

Thank you in advance

Decio

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: JS code error on UI client but not on web client

    Thank you Lu Hao, problem sorted

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: JS code error on UI client but not on web client

    Hi Decio ,

    Please make sure you are pissing execution context and the function calling using namespace like below.

    2018_2D00_12_2D00_31_5F00_15_2D00_27_2D00_45_5F00_UUI.png

  • Verified answer
    LuHao Profile Picture
    LuHao 40,872 on at
    RE: JS code error on UI client but not on web client

    Hi Decio,

    On UCI, please use var executionContext = primaryControl, instead of var formContext = executionContext.getFormContext().

    We can get the form field values properties using executionContext itself in Dynamics 365.

    var executionContext = primaryControl;
    var triggervalue = executionContext.getAttribute("acc1_startclocktrigger");

    You could refer to this article. The problem with this post is very similar to yours.

    Hope this helps.

    Best Regards,

    Lu Hao

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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